FOR loop

With the FOR loop one can program repeated processes.
Syntax:


INT_Var :INT;


FOR <INT_Var> := <INIT_VALUE> TO <END_VALUE> {BY
<stepsize>} DO

    <instructions>

END_FOR;

The part in braces {} is optional.

The <Instructions> are executed as long as the counter <INT_Var> is not greater than the <END_VALUE>. This is checked before executing the <Instructions> so that the <instructions> are never executed if <INIT_VALUE> is greater than <END_VALUE>. When <Instructions> are executed, <INT_Var> is always increased by <Step size>. The step size can have any integer value. If it is missing, then it is set to 1. The loop must also end since <INT_Var> only becomes greater.

Example:

FOR counter:=1 TO 5 BY 1 DO

    Var1:=Var1*2;

END_FOR;

Erg:=Var1;

Let us assume that the default setting for Var1 is the value 1. Then it will have the value 32 after the FOR loop.

The <END_VALUE> can not be the limit of the counter <INT_VAR>.E.g. if the variable counter is of type SINT, and if <END_VALUE> is 127, you get an endless loop.