BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – BRANCH
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 133
BRANCH
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
BRANCH Offset, ( Address0, Address1, ...AddressN )
BRANCH Offset, [ Address0, Address1, ...AddressN ]
Function
Go to the address specified by offset (if in range).
• Offset is a variable/constant/expression (0 – 255) that specifies the
index of the address, in the list, to branch to (0 – N).
• Addresses are labels that specify where to go. BRANCH will ignore
any list entries beyond offset 255.
Quick Facts
Table 5.3: BRANCH Quick Facts.
BS1 All BS2 Models
Limit of
Address Entries
Limited only by memory 256
Related
Commands
None ON...GOTO
Explanation
The BRANCH instruction is useful when you want to write something like
this:
IF value = 0 THEN Case_0 ' when value is 0, jump to Case_0
IF value = 1 THEN Case_1 ' when value is 1, jump to Case_1
IF value = 2 THEN Case_2 ' when value is 2, jump to Case_2
You can use BRANCH to organize this into a single statement:
BRANCH value, [Case_0, Case_1, Case_2]
This works exactly the same as the previous IF...THEN example. If the
value isn’t in range (in this case if value is greater than 2), BRANCH does
nothing and the program continues with the next instruction after
BRANCH.
BRANCH can be teamed with the LOOKDOWN instruction to create a
simplified SELECT...CASE statement. See LOOKDOWN for an example.
BS1 syntax not shown here.
NOTE: Expressions are not allowed as
arguments on the BS1.
1
All
2
1
1