10 while loop, While loop, Drive plc developer studio – Lenze DDS v2.3 User Manual

Page 47

Advertising
background image

Drive PLC Developer Studio

Programming languages

4-9

l

DDS EN 2.3

4.3.10

WHILE loop

The WHILE loop can be used like a FOR loop, the only difference being that the cancel condition can
be any Boolean expression.

Syntax:

WHILE

<Boolean expression> DO

<instructions>

END_WHILE

;

The <instructions> will be executed again and again until the
<Boolean_expression> returns TRUE

.

If <Boolean_expression> is FALSE on first evaluation already, the <instructions> will
never be executed.

If <Boolean_expression> is never FALSE the <instructions> will be repeated
endlessly, forcing a runtime error.

Note!

The programmer himself must ensure that endless loops do not occur by changing the condition
in the instruction part of the loop, for instance change the counter settings. Otherwise the task with
the endless loop would overflow.

Example:

WHILE

Counter<>0 DO

Var1:=Var1*2;
Counter:=Counter-1;

END_WHILE

The WHILE and the REPEAT loops are more powerful in a way than the FOR loop since the number
of loop cycles does not need to be known prior to loop execution.

In some cases, these two loop types will have to be sufficient.

If the number of loop cycles is known, however, a FOR loop should be preferred.

Task overflows can also occur in FOR loops.

(

^ 4-8)

Show/Hide Bookmarks

Advertising