BASIC stamp manual v2.2

DO...LOOP – BASIC Stamp Command Reference
Page 176 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
For example:
' {$PBASIC 2.5}
AckPin PIN 0
Pressed CON 1
DO
DEBUG "Error...", CR
IF (AckPin = Pressed) THEN EXIT ' wait for user button press
PAUSE 2000
LOOP
GOTO Initialize ' re-initialize system
In this case the DO...LOOP will continue until the pin called AckPin is
equal to Pressed (1), and then the loop will terminate and continue at the
line GOTO Initialize.
More often than not, you will want to test some condition to determine
whether the code block should run or continue to run. A loop that tests the
condition before running code block is constructed like this:
' {$PBASIC 2.5}
reps VAR Nib
DO WHILE (reps < 3) ' test before loop statements
DEBUG "*"
reps = reps + 1
LOOP
In this program the instructions DEBUG "*" and reps = reps + 1 will not
run unless the WHILE condition evaluates as True. Another way to write
the loop is like this:
' {$PBASIC 2.5}
reps VAR Nib
DO
DEBUG "*"
reps = reps + 1
LOOP UNTIL (reps >= 3) ' test after loop statements
The difference is that with this loop, the code block will always be run at
least once before the condition is tested and will continue to run as long as
the UNTIL condition evaluates as False.