GOSUB line
number
Tranfers
program control
to the subroutine beginning
at
the specified line number
and
stores an address to
RETURN
to after the
subroutine
is
complete. When the
Computer encounters a RETURN statement in the
subroutine, it will then return
control to the statement which
follows
GOSUB.
If you don't RETURN, the previously stored address
will not be deleted from the area
of memory
used
for saving information, called the stack. The stack
might
eventually overflow,
but,
even more importantly, this address
might
be read
incorrectly during another operation, causing
a
hard-to-find program error. So. . .
always
RETURN
from your subroutines. GOSUB , like GOTO may be
preceded
by a
test statement. See IF,THEN,ELSE,ON...GOSUB.
Example
Program:
100
GOSUB 200
110
PRINT "
BACK F ROM
THE SUB
ROUT
I
NE
"
:
E ND
200 PRINT
"EXECUTING
THE
SUBROUTINE"
210 RETURN
READY
>RUN
EXECUTING
THE
SUBROUTINE
BACK
FROM THE
SUBROUTINE
Control
branches
from line 100
to
the
subroutine beginning at line 200. Line 210
instructs
Computer to return to
the statement immediately following GOSUB
,
that
is,
line 1 10.
RETURN
Ends
a
subroutine
and returns
control to statement immediately following the most
recently
executed GOSUB. If RETURN is
encountered without execution
of a
matching GOSUB, an error will occur. See GOSUB.
153