Syntax:
Do [{While | Until} condition]
...
program code
...
<condition> Exit Do
...
Loop [{While | Until} condition]Command Availability:
Available on all microcontrollers.
Explanation:
The Do command will cause the code between the Do and the Loop to run
repeatedly while condition is true or until condition is true,
depending on whether While or Until has been specified.
Note that the While or Until and the condition can only be specified
once, or not at all. If they are not specified, then the code will
repeat endlessly.
Optionally, you can specify a condition to EXIT the Do-Loop immediately.
Example 1:
'This code will flash a light until the button is pressed
#chip 12F629, 4
#define BUTTON GPIO.3
#define LIGHT GPIO.5
Dir BUTTON In
Dir LIGHT Out
Do Until BUTTON = 1 ' <<< the Do...Loop this page documents
PulseOut LIGHT, 1 s
Wait 1 s
LoopKey line: Do Until BUTTON = 1 — the loop body repeats until BUTTON becomes true; with Until the test happens before each pass.
Example 2:
This code will also flash a light until the button is pressed. This
example uses EXIT DO within a continuous loop.
#chip 12F629, 4
#define BUTTON GPIO.3
#define LIGHT GPIO.5
Dir BUTTON In
Dir LIGHT Out
Do
PulseOut LIGHT, 1 s
Wait 1 s
if BUTTON = 1 then EXIT DO
LoopSee Also:
- Conditions — background on how conditions are evaluated
- For — fixed-count loop alternative when the number of iterations is known
- If — conditional execution without looping
- PulseOut — generating a timed pulse, as used in the example above
- Wait — introducing a fixed delay, as used in the example above

