FOR  TO  BY  END_FOR

Statement - Execute iterations of statements.

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.

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

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;

See Also