BASIC stamp manual v2.2

RETURN – BASIC Stamp Command Reference
Page 376 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
it would see the RETURN again (although it didn't GOSUB to that routine
this time) and because there wasn't a previous place to return to, the
BASIC Stamp will start the entire program over again. This would cause
an endless loop. The important thing to remember here is to always make
sure your program doesn't allow itself to "fall into" a subroutine.
Demo Program (RETURN.bs2)
' RETURN.BS2
' This program demonstrates a potential bug caused by allowing a program to
' "fall into" a subroutine. The program was intended to indicate that it
' is "Starting...", then "Executing Subroutine,", then "Returned..." from
' the subroutine and stop. Since we left out the END command (indicated in
' the comments), the program then falls into the subroutine, displays
' "Executing..." again and then RETURNs to the start of the program and
' runs continuously in an endless loop.
' {$STAMP BS2}
Reset:
DEBUG "Starting Program", CR ' show start-up
Main:
PAUSE 1000
GOSUB Demo_Sub ' call the subroutine
PAUSE 1000
DEBUG "Returned from Subroutine", CR ' show that we're back
PAUSE 1000
' <-- Forgot to put END here
Demo_Sub:
DEBUG " Executing Subroutine", CR ' show subroutine activity
RETURN
1
A
ll
2
NOTE: This example program can be
used with the BS1 and all BS2 models
by changing the $STAMP directive
accordin
g
l
y
.