beautypg.com

9 for loop, For loop, Drive plc developer studio – Lenze DDS v2.3 User Manual

Page 46

background image

Drive PLC Developer Studio

Programming languages

4-8

l

DDS EN 2.3

4.3.9

FOR loop

Use the FOR loop to program repetitive procedures.

Syntax:

INT_Var :INT;

FOR

:= TO {BY } DO

END_FOR

;

The part in curly brackets {} is optional.

The are executed as long as the counter is not greater than
the.

A check is performed before the are executed so that the

will never be executed if is greater than .

Whenever the section has been executed, will be increased
by .

The step size can have any integer value. If no other step size is specified, step size 1 will be
used. The loop must terminate because will only become greater.

If is greater than and is negative, the FOR
loop is counted in opposite direction.

If is less than and is negative, the FOR loop
will not be executed.

Example:

FOR

Counter:=1 TO 5 BY 1 DO

Var1:=Var1*2;

END_FOR

;

Res:=Var1;

Assuming that the variable Var1 has been pre-assigned value 1, it will be 32 after the FOR loop.

Caution!

must not be the limit value of the counter .

If, for instance, the variable Counter is of type SINT, must not be 127 since
otherwise the loop would be endless.

After completion of the FOR loop, Counter has a value 6.

Show/Hide Bookmarks