BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – DO...LOOP
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 175
DO…LOOP
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
DO { WHILE | UNTIL Condition(s) }
Statement(s)
LOOP { WHILE | UNTIL Condition(s) }
Function
Create a repeating loop that executes the Statement(s), one or more
program lines that form a code block, between DO and LOOP, optionally
testing Condition(s) before or after the Statement(s).
• Condition is an optional variable/constant/expression (0 - 65535)
which determines whether the loop will run or terminate. Condition
must follow WHILE or UNTIL.
• Statement is any valid PBASIC instruction.
Quick Facts
Table 5.18: DO...LOOP Quick
Facts.
All BS2 Models
Maximum Nested Loops
16
WHILE Condition Evaluation
Run loop if Condition evaluates as true
UNTIL Condition Evaluation
Terminate loop if Condition evaluates as true
Related Commands
FOR...NEXT and EXIT
Explanation
DO...LOOP loops let a program execute a series of instructions indefinitely
or until a specified condition terminates the loop. The simplest form is
shown here:
' {$PBASIC 2.5}
DO
DEBUG "Error...", CR
PAUSE 2000
LOOP
In this example the error message will be printed on the Debug screen
every two seconds until the BASIC Stamp is reset. Simple DO...LOOP
loops can be terminated with EXIT.
All
2
NOTE: DO...LOOP requires the
PBASIC 2.5 compiler directive.