2
1
2
e
Table 5.68: RETURN Quick Facts.
1
NOTE: On the BS1, a RETURN
without a GOSUB will return the
program to the last GOSUB (or will
end the program if no GOSUB was
executed).
W
ATCH OUT FOR SUBROUTINES THAT
"
YOUR PROGRAM CAN
FALL INTO
5: BASIC Stamp Command Reference – RETURN
RETURN
2
2
RETURN
sx
p
Function
Return from a subroutine, assuming there was a previous GOSUB
executed.
Quick Facts
Maximum
number of
RETURNS per
program
Explanation
RETURN sends the program back to the address (instruction) immediately
following the most recent GOSUB. If RETURN is executed without a prior
GOSUB, the BASIC Stamp will return to the first executable line of the
program; usually resulting in a logical bug in the code. See the GOSUB
command for more information.
The example below will start out by GOSUB'ing to the section of code
beginning with the label Hello. It will print "Hello my friend." on the
screen then RETURN to the line after the GOSUB... which prints "How are
you?" and ENDs.
GOSUB Hello
DEBUG "How are you?"
END
Hello:
DEBUG "Hello my friend.", CR
RETURN
There's another interesting lesson here; what would happen if we removed
."
the END command from this example? Since the BASIC Stamp reads the
code from left to right / top to bottom (like the English language) once it
had returned to and run the "How are you?" line, it would naturally "fall
into" the Hello routine again. Additionally, at the end of the Hello routine,
it would see the RETURN again (although it didn't GOSUB to that routine
BS1
BS2
BS2e BS2sx BS2p
BS1, BS2, BS2e, BS2sx and BS2p
Unlimited. However, the number of GOSUBs are limited. See GOSUB
for more information.
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 265
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?