NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.
' 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
row VAR Nib
Setup:
col = 0
Main:
DO WHILE (col < 10) ' attempt 10 iterations
FOR row = 0 TO 15 ' attempt 16 iterations
IF (row > 9) THEN EXIT ' terminate when row > 9
DEBUG CRSRXY, (col * 8), row, ' print col/row at location
DEC col, "/", DEC row, CR
NEXT
col = col + 1 ' update column
IF (col = 3) THEN EXIT ' terminate when col = 3
LOOP
END
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012