BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – EXIT
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 189
EXIT
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
EXIT
Function
Causes the immediate termination of a loop construct (DO...LOOP,
FOR...NEXT).
Quick Facts
Table 5.24: EXIT Quick Facts.
All BS2 Models
Maximum EXITs per Loop
16
Related Commands
DO...LOOP and FOR...NEXT
Explanation
The EXIT instruction allows a program to terminate a loop structure
before the loop limit test is executed. While not required, EXIT is usually
used as part of an IF...THEN construct to test a secondary condition for
terminating a loop, or for testing a termination condition of an
unconditional DO...LOOP structure.
For example, the following subroutine will send characters from a DATA
statement to a serial port until a 0 byte is encountered in the data:
' {$PBASIC 2.5}
DO
READ eeAddr, char ' get character from DATA statement
eeAddr = eeAddr + 1 ' update address pointer
IF (char = 0) THEN EXIT ' if 0, end of string
DEBUG char ' otherwise, transmit the character
LOOP ' get next character
RETURN
Demo Program (EXIT.bs2)
' EXIT.bs2
' This program demonstrates the early termination of DO...LOOP and
' FOR..NEXT loop structures. IF...THEN is used to test a condition
' and when true, EXIT will terminate the loop.
' {$STAMP BS2}
' {$PBASIC 2.5}
col VAR Nib
All
2
NOTE: EXIT requires the
PBASIC 2.5 compiler directive.
NOTE: This example program can be
used with all BS2 models by changing
the $STAMP directive accordingly.
All
2