<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>@break Archives - Artificial Intelligence</title>
	<atom:link href="https://www.aiuniverse.xyz/tag/break/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aiuniverse.xyz/tag/break/</link>
	<description>Exploring the universe of Intelligence</description>
	<lastBuildDate>Tue, 05 Dec 2023 09:57:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Blade Looping Directives in Larvel</title>
		<link>https://www.aiuniverse.xyz/blade-looping-directives-in-larvel/</link>
					<comments>https://www.aiuniverse.xyz/blade-looping-directives-in-larvel/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Kr.]]></dc:creator>
		<pubDate>Tue, 05 Dec 2023 09:44:38 +0000</pubDate>
				<category><![CDATA[laravel]]></category>
		<category><![CDATA[@break]]></category>
		<category><![CDATA[@continue]]></category>
		<category><![CDATA[@foreach]]></category>
		<category><![CDATA[@forelse]]></category>
		<category><![CDATA[Blade directives]]></category>
		<category><![CDATA[Blade Looping Directives in Larvel]]></category>
		<category><![CDATA[Blade templates]]></category>
		<category><![CDATA[Conditional looping]]></category>
		<category><![CDATA[Data rendering]]></category>
		<category><![CDATA[Iteration]]></category>
		<category><![CDATA[Loop control]]></category>
		<guid isPermaLink="false">https://www.aiuniverse.xyz/?p=18206</guid>

					<description><![CDATA[<p>Blade looping directives are used to iterate over collections of data in Laravel Blade templates. There are three main looping directives: 1. @foreach: This directive allows you <a class="read-more-link" href="https://www.aiuniverse.xyz/blade-looping-directives-in-larvel/">Read More</a></p>
<p>The post <a href="https://www.aiuniverse.xyz/blade-looping-directives-in-larvel/">Blade Looping Directives in Larvel</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-54.png" alt="" class="wp-image-18213" width="836" height="405" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-54.png 787w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-54-300x145.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-54-768x372.png 768w" sizes="(max-width: 836px) 100vw, 836px" /></figure>



<p>Blade looping directives are used to iterate over collections of data in Laravel Blade templates. There are three main looping directives:</p>



<ol class="wp-block-list">
<li>@foreach</li>



<li>@for</li>



<li>@while</li>
</ol>



<h2 class="wp-block-heading">1. @foreach:</h2>



<p> This directive allows you to loop over an array or collection. It has the following syntax:</p>



<pre class="wp-block-code"><code>
   @foreach($items as $item)
       // Code to be executed for each iteration
   @endforeach

</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;div class = "container"&gt;
        @php
           $arr = &#91;1,2,3,4,5,6,7,8,9,10];
        @endphp
        @foreach ($arr as $i)
            &lt;h2&gt;{{$i}}&lt;/h2&gt;
        @endforeach
    &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="346" height="547" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-49.png" alt="" class="wp-image-18207" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-49.png 346w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-49-190x300.png 190w" sizes="(max-width: 346px) 100vw, 346px" /></figure>



<h2 class="wp-block-heading">2. @for:</h2>



<p>The <code>@for</code> directive allows you to loop a specific number of times. It has the following syntax:</p>



<pre class="wp-block-code"><code>
   @for($i = 0; $i &lt; $count; $i++)
       // Code to be executed for each iteration
   @endfor
   </code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;div class= "container"&gt;
 @for ($i = 1; $i &lt; 10; $i++)
      &lt;h2&gt;
         {{$i}}
      &lt;/h2&gt;
 @endfor
&lt;/body&gt;

&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="355" height="484" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-50.png" alt="" class="wp-image-18208" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-50.png 355w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-50-220x300.png 220w" sizes="(max-width: 355px) 100vw, 355px" /></figure>



<h2 class="wp-block-heading">3. @while:</h2>



<p>This directive allows you to execute a block of code repeatedly as long as a specific condition is met. It has the following syntax:</p>



<pre class="wp-block-code"><code>
   @while($condition)
       // Code to be executed while the condition is true
   @endwhile
</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;div class= "container"&gt;
        @php
        $i = 1;
        @endphp
        @while($i&lt;=10)
           &lt;h2&gt; {{$i}} &lt;/h2&gt;
        @php $i++; @endphp
        @endwhile

    &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-51.png" alt="" class="wp-image-18209" width="321" height="589" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-51.png 321w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-51-163x300.png 163w" sizes="auto, (max-width: 321px) 100vw, 321px" /></figure>



<h2 class="wp-block-heading">Loop Variable:</h2>



<p>The Loop variable is a special variable that is available within loops. It provides information about the current iteration of the loop. Some of the properties of the Loop variable include:</p>



<ul class="wp-block-list">
<li><strong>index: </strong>The current iteration number (starting from 0)</li>



<li><strong>first:</strong> Whether this is the first iteration</li>



<li><strong>last:</strong> Whether this is the last iteration</li>



<li><strong>even:</strong> Whether this is an even iteration</li>



<li><strong>odd:</strong> Whether this is an odd iteration</li>
</ul>



<h2 class="wp-block-heading">@continue:</h2>



<p>The @continue directive is used to skip the current iteration of a loop and continue to the next iteration.</p>



<p><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>@foreach($items as $item)
    @if(some_condition)
        @continue
    @endif
    // Code here executes only if the condition is false for the current item
    &lt;li&gt;{{ $item }}&lt;/li&gt;
@endforeach
</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;div class = "container"&gt;
     @for ($i= 1; $i&lt;= 10; $i++)
         @if ($i==5)
         @continue
        
    @endif
           {{$i}}
           @endfor
   &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="570" height="291" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-52.png" alt="" class="wp-image-18210" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-52.png 570w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-52-300x153.png 300w" sizes="auto, (max-width: 570px) 100vw, 570px" /></figure>



<h2 class="wp-block-heading">@break:</h2>



<p>The @break directive is used to terminate a loop and exit the loop body.</p>



<p><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>@foreach($items as $item)
    @if(some_condition)
        @break
    @endif
    &lt;li&gt;{{ $item }}&lt;/li&gt;
@endforeach
</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"&gt;

&lt;/head&gt;

&lt;body&gt;
 &lt;div class = "container"&gt;
     @for ($i= 1; $i&lt;= 10; $i++)
         @if ($i==5)
         &lt;!-- @continue --&gt;
         @break
    @endif
           {{$i}}
           @endfor
   &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="530" height="248" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-53.png" alt="" class="wp-image-18211" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-53.png 530w, https://www.aiuniverse.xyz/wp-content/uploads/2023/12/image-53-300x140.png 300w" sizes="auto, (max-width: 530px) 100vw, 530px" /></figure>



<p>These are just a few examples of the looping directives available in Laravel&#8217;s Blade templating engine. Thanks for Visiting.</p>
<p>The post <a href="https://www.aiuniverse.xyz/blade-looping-directives-in-larvel/">Blade Looping Directives in Larvel</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aiuniverse.xyz/blade-looping-directives-in-larvel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
