FOR   TO   BY   END_FOR

Statement - Iteration of statement execution.

Syntax

    FOR <index> := <minimum> TO <maximum> BY <step> DO
        <statements>
    END_FOR;

index = DINT internal variable used as index
minimum = DINT expression: initial value for index
maximum = DINT expression: maximum allowed value for index
step = DINT expression: increasing step of index after each iteration (default is 1)

Remarks

The "BY <step>" statement can be omitted. The default value for the step is 1.

ST Language

iArrayDim := 10;

(* resets all items of the array to 0 *)
FOR iPos := 0 TO (iArrayDim - 1) DO
   MyArray[iPos] := 0;
END_FOR;

(* set all items with odd index to 1 *)
FOR iPos := 1 TO 9 BY 2 DO
   MyArray[ipos] := 1;
END_FOR;

FBD Language

Not available

LD Language

Not available

IL Language:

Not available

See also

IF   WHILE   REPEAT   CASE    EXIT