Gosub – Remote Processing CAMBASIC User Manual
Page 86

Comm ands - 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 progr am, and a subroutine may be called from
within another subroutine.
The RE TUR N statement cau ses CAM BASIC to br anch back to the statement follow ing the most
recent G OSU B statement. A subr outine ma y contain m ore than o ne RET URN statement, should
logic dictate a return at different points in the subroutine. Subroutines may appear anyw here in the
p r o gr a m .
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 exe cution of the G OSU B statement is ind ependent of the location of the target line in
the progra m. No run– time search oc curs.
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