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

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
END_WHILE
;
•
The
.
•
If
never be executed.
•
If
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.
Show/Hide Bookmarks