FOR
loop has a strictly certain number of iterations (repetitions).FOR <loop variable> = <initial value> TO/DOWNTO <final value> [step = 1]
<the loop body>
END
<loop variable>
- a variable used as a counter for iterations
<initial value>
- a value of the loop variable before the first iteration (any value including a model identifier)
TO
or DOWNTO
- increment or decrement the loop variable between iterations
<final value>
- a value of the loop variable after the last iteration (any value including a model identifier)
<step>
- an optional value the loop variable will be incremented or decremented with between iterations. By default it is equal to 1
.loop variable
is not declared with any type before the loop it gets the Integer
type. If initial value
, final value
or step
are variables, they get the same type the loop variable
has To use floating-point numbers for the initial and final values, declare the loop variable with the Float
type.$MyCounter
and $final
both have the Float
type after the loop.WHILE <loop condition>
<the loop body>
END
loop condition
- a single conditional opcode
loop body
- commands to execute on each iteration; can be omittedWHILE
loop works while the loop condition is true. The condition is evaluated before a loop iteration. Hence, if the condition is false, the loop body never gets executed.Break
command.Break
and Continue
.REPEAT
<the loop body>
UNTIL <loop condition>
loop body
- commands to execute on each iteration; can be omitted
loop condition
- a single conditional opcodeREPEAT..UNTIL
loop executes until the loop condition returns false. The condition is evaluated after iteration therefore the loop is guaranteed to be executed at least once.Break
and Continue
.Continue
command. Break
command causes the loop to stop immediately and proceed to the command after the loop body.jf Continue
) or serve as a standalone statement.