5: BASIC Stamp Command Reference – RETURN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 265
RETURN
BS1 BS2 BS2e BS2sx BS2p
RETURN
Function
Return from a subroutine, assuming there was a previous GOSUB
executed.
Quick Facts
BS1, BS2, BS2e, BS2sx and BS2p
Maximum
number of
RETURNS per
program
Unlimited. However, the number of GOSUBs are limited. See GOSUB
for more information.
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
1
2
e
2
sx
2
p
2
W
ATCH OUT FOR SUBROUTINES THAT
YOUR PROGRAM CAN
"
FALL INTO
."
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).
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...