@while - Looping Until a Condition is Met
The @while directive in Ahmed PHP Template Engine allows you to execute a block of code repeatedly as long as a specified condition evaluates to true.
Syntax
@while(condition)
// Code to execute
@endwhileExample
@while($count <= 3)
<p>Count: {{ $count }}</p>
@php $count++ @endphp
@endwhileOutput (if $count = 1 initially)
$count = 1 initially)<p>Count: 1</p>
<p>Count: 2</p>
<p>Count: 3</p>Notes
The loop continues execution as long as
conditionistrue.Ensure the condition eventually becomes
falseto avoid infinite loops.You can modify the loop variable inside the loop using
@php.
Last updated