Iteration
While and Repeat Loops
WHILE and REPEAT loops provide expression group retry while conditional Boolean expression is true. If the conditional expression is always true, loops become infinite.
![]() | Syntax:
|
The condition in WHILE loop is checked before loop start. If the Boolean expression initially has FALSE value, the loop body is not executed.
![]() | Syntax:
|
Condition in REPEAT loop is checked after loop body execution. If Boolean expression initially has FALSE value, loop body is executed ones. Well-formed WHILE or REPEAT loop should necessarily change variables making end condition in loop body. It gradually approaches to end condition. If this is not done, loop will be infinite.
![]() | Example:
|
for Loop
FOR loop provides preset number of expression group retries.
![]() | Syntax:
|
Before loop execution, counter gets initial value. After that, loop body is repeated till counter value exceeds end value. Counter increases on every loop. Initial and end values and step can be both constants and expressions. Counter is changed after loop body execution. If end value is larger than initial value, loop won't be executed at positive increment. If initial and end values are equal, loop body is executed once. Part of BY construction in brackets is optional, it defines counter growth increment. Counter increases by one in every iteration by default. Variable of any integer type can be used as counter.
![]() | Example:
|
Was this page helpful?
