@do @whileCond - Do-While Loop
The @do and @whileCond directives in Ahmed PHP Template Engine allow you to create a do-while loop, which executes the block of code at least once before checking the condition.
Syntax
@do
// Code to execute
@whileCond(condition)condition: The expression that determines whether the loop continues.
Description
The block inside
@doruns first, regardless of the condition.After execution,
@whileCondchecks the condition; if true, the loop repeats.Useful for cases where you need to ensure the loop executes at least once.
Example
@define(counter, 1)
@do
<p>Iteration: @counter</p>
@define(counter, counter + 1)
@whileCond(counter <= 3)Expected Output
Notes
The loop guarantees one execution before checking the condition.
Ensure the condition changes within the loop to prevent infinite loops.
Similar to
@while, but always executes at least once before checking.
Last updated