BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – ON
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 289
ON
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
ON Offset GOTO Address1, Address2, ...AddressN
ON Offset GOSUB Address1, Address2, ...AddressN
Function
GOTO or GOSUB to the Address specified by Offset (if in range). ON is
similar in operation to BRANCH with the exception that program
execution can optionally return to the line following ON (if using
ON…GOSUB).
• Offset is a variable/constant/expression (0 - 255) that specifies the
index (0 - N) of the address, in the list, to GOTO or GOSUB to.
• Address is a label that specifies where to go for a given Offset. ON
will ignore any list entries beyond offset 255.
Quick Facts
Table 5.61: ON Quick Facts.
All BS2 Models
Limit of Address
Entries
256
Maximum GOSUBs
per Program
255 (each ON…GOSUB counts as one GOSUB,
regardless of number of address list entries)
Maximum Nested
GOSUBS
4
Related Commands
BRANCH, GOTO and GOSUB
Explanation
The ON instruction is like saying, “Based ON the value of Offset, GOTO or
GOSUB to one of these Addresses.” ON is useful when you want to write
something like this:
IF (value = 0) THEN GOTO Case_0 ' "GOTO" jump table
IF (value = 1) THEN GOTO Case_1
IF (value = 2) THEN GOTO Case_2
- or -
IF (value = 0) THEN GOSUB Case_0 ' "GOSUB" jump table
IF (value = 1) THEN GOSUB Case_1
IF (value = 2) THEN GOSUB Case_2
NOTE: ON requires PBASIC 2.5.
All
2
All
2