# BRANCH

BRANCH Examples

Syntax : BRANCH Offset, (Address1, Address2, ...AddressN)

Syntax : BRANCH Offset, [Address1, Address2, ...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.

* Note: expressions are not allowed as arguments on the BS1.

## Quick Facts

| BS1 | BS2 Family
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:

    Test_Value:
      IF value = 0 THEN Case_0              ' if value is 0, jump to Case_0
      IF value = 1 THEN Case_1              ' if value is 1, jump to Case_1
      IF value = 2 THEN Case_2              ' if 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)

      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.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012