BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – GOTO
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 213
GOTO
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
GOTO Address
Function
Go to the point in the program specified by Address.
• Address is a label that specifies where to go.
Quick Facts
Table 5.30: GOTO Quick Facts.
BS1 All BS2 Models
Related
Commands
BRANCH and GOSUB ON...GOTO, BRANCH and GOSUB
Max. GOTOs
per Program
Unlimited, but good programming practices
suggest using the least amount possible.
Explanation
The GOTO command makes the BASIC Stamp execute the code that starts
at the specified Address location. The BASIC Stamp reads PBASIC code
from left to right / top to bottom, just like in the English language. The
GOTO command forces the BASIC Stamp to jump to another section of
code.
A common use for GOTO is to create endless loops; programs that repeat a
group of instructions over and over. For example:
Start:
DEBUG "Hi", CR
GOTO Start
The above code will print "Hi" on the screen, over and over again. The
GOTO Start line simply tells it to go back to the code that begins with the
label Start. Note: colons ( : ) are placed after labels, as in “Start:” to further
indicate that they are labels, but the colon is not used on references to
labels such as in the “GOTO Start” line.
Demo Program (GOTO.bs2)
' GOTO.bs2
' This program is not very practical, but demonstrates the use of GOTO to
' jump around the code. This code jumps between three different routines,
' each of which print something different on the screen. The routines are
' out of order for this example.
1
A
ll
2
1
A
ll
2
NOTE: This is written for the BS2 but
can be used for the BS1 and all other
BS2 models as well, by modifying the
$STAMP directive accordingly.