While loop, L-force | plc designer – Lenze PLC Designer PLC Designer (R2-x) User Manual

Page 60

Advertising
background image

L-force | PLC Designer

What is What in PLC Designer

58

DMS 3.2 EN 02/2011 TD29



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.

Note!

<END_VALUE> must not be equal to the limit value of the counter <INT_VAR>. For
example: If the variable Counter is of type SINT and if <END_VALUE> is 127, you will
get an endless loop.

WHILE loop

The WHILE loop can be used like the FOR loop with the difference that the break-off
condition can be any Boolean expression. This means you indicate a condition which,
when it is fulfilled, the loop will be executed.

Syntax:

WHILE

<Boolean expression>

<Instructions>

END_WHILE;

The <Instructions> are repeatedly executed as long as the <Boolean_expression>
returns TRUE. If the <Boolean_expression> is already FALSE at the first evaluation,
then the <Instructions> are never executed. If <Boolean_expression> never assumes
the value FALSE, then the <Instructions> are repeated endlessly which causes a
relative time delay.

Advertising