
Commands - 53
GOSUB
Statement
SYNTAX: GOS UB line/label
.
.
.
RETURN
PURPOSE: To branch to and return from a subroutine.
REMARK S: line/label is the beginning of the subroutine.
A subroutine may be called any number of times in a program, and a subroutine may be called from
within another subroutine.
The RETUR N statement causes CAM BASIC to branch back to the statement follow ing the most
recent G OSUB statement. A subroutine may contain m ore than one RET URN statement, should
logic dictate a return at different points in the subroutine. Subroutines may appear anywhere in the
program.
To prevent inadvertent entry into the subroutine, you may put an EN D or GO TO statement in front
of it to direct program control around the subroutine.
NOTE: The execution of the G OSUB statement is independent of the location of the target line in
the program. No run– time search occurs.
When a label is used with GOSUB, a statement cannot follow GOSUB on the same line.
EXAMPLE: 10 GOSUB 40
20 PRINT "Back from subroutine"
30 END
40 PRINT "subroutine";
50 PRINT "in";
60 PRINT "progress"
70 RETURN
RUN
subroutine in progress
Back from subroutine
Komentáře k této Příručce