@break and @continue - Loop Control
The @break and @continue directives in Ahmed PHP Template Engine allow you to control the flow of loops by either exiting the loop entirely (@break) or skipping the current iteration (@continue).
Syntax
@break
@continue@breakexits the loop immediately.@continueskips the current iteration and moves to the next one.
Example
@foreach(numbers as number)
@if(number == 3)
@break
@endif
<p>{{ number }}</p>
@endforeachOutput
<p>1</p>
<p>2</p>(The loop stops when number == 3.)
Using @continue
@continueOutput
(The number 2 is skipped.)
Notes
@breakis useful when you need to stop a loop early based on a condition.@continueis helpful when you want to skip certain iterations without stopping the loop.Both directives work inside
@for,@foreach, and@whileloops.
Previous@unless - Conditional Rendering for False ValuesNextString Case Conversion - @strtoupper, @strtolower, and @ucfirst
Last updated