DO ... LOOP |
DO { WHILE | UNTIL Condition }
Statement(s)
{ EXIT }
LOOP
DO
Statement(s)
{ EXIT }
LOOP { UNTIL | WHILE Condition }
Function
Create a repeating loop that executes the program lines between DO and
LOOP, optionally testing before or after the loop statements.
Explanation
DO...LOOP loops let your program execute a series of instructions
indefinitely, or until a specified condition terminates the loop. The simplest
form is shown here:
Alarm_On: DO HIGH Alarm_LED PAUSE 500 LOW Alarm_LED PAUSE 500 LOOP
In this example the alarm LED will flash until the SX is reset. DO...LOOP allows for condition testing before and after the loop statements as show in the examples below.
Alarm_On: DO WHILE AlarmStatus = 1 HIGH Alarm_LED PAUSE 500 LOW Alarm_LED PAUSE 500 LOOP RETURN
Alarm_On: DO HIGH Alarm_LED PAUSE 500 LOW Alarm_LED PAUSE 500 LOOP UNTIL AlarmStatus = 0 RETURN
When the second form is used the loop statements will run at least once before the condition test.
Related instructions: FOR...NEXT and EXIT