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.
' ON-GOTO.BS2
' This program shows how the value of idx controls the destination of the
' ON...GOTO instruction.
' {$STAMP BS2}
' {$PBASIC 2.5}
idx VAR Byte
Main:
DEBUG "idx: ", DEC idx, " "
ON idx GOTO Case_0, Case_1, Case_2 ' if idx = 0..2 goto label
DEBUG "ON..GOTO target error.", CR ' message if idx is out of range
Update:
idx = idx + 1 // 4 ' force idx to be 0..3
PAUSE 1000
GOTO Main
Case_0:
DEBUG "Running Case_0 routine", CR
GOTO Update
Case_1:
DEBUG "Running Case_1 routine", CR
GOTO Update
Case_2:
DEBUG "Running Case_2 routine", CR
GOTO Update
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012