Control Flow
while
$while / $endWhile — While Loop
$while[condition] repeats the block up to $endWhile for as long as the condition is true. Like $if and $for, it is a structural token handled by the BDFD parser.
Syntax
$while[condition]
...
$endWhile
Parameters
| Parameter | Description | Required |
|---|---|---|
condition |
Evaluated before every iteration with the same rules as $if: the text true / false, or a comparison left operator right. Anything else raises “Invalid condition”. |
Yes |
Exactly one argument is required: $while[a;b] is refused with “Expected one while condition.”
Behavior
- The condition is re-evaluated at the start of each iteration, so it can depend on a variable changed inside the block. If it is false the first time, the block never runs.
- Inside the block,
$i,$loopIndex(zero-based) and$loopCount(one-based) give the iteration number. $breakleaves the loop and$continuejumps to the next evaluation of the condition (see $break and $continue).- The loop must be closed with
$endWhile; a missing one is a parse error (“Missing $endwhile.”). - A loop whose condition never becomes false is stopped by the engine’s execution limits (“Execution step limit exceeded.”).
Examples
Count with a temporary variable
$var[n;0]
$while[$var[n]<3]
Step $var[n]
$var[n;$sum[$var[n];1]]
$endWhile
Leave early
$while[true]
$if[$i==2]
$break
$endif
Round $loopCount
$endWhile