
RPBASIC-52 PROGRAMMING GUIDE
2-44
GOSUB
Syntax: GOSUB line number
...
line number program statements
RETURN
Function: Transfers program control to the specified line number. The RETURN causes execution to resume at
the program statement after GOSUB.
Mode: Run
Use: 100 FOR A=1 to 20 : GOSUB 200 : NEXT A : END
200 PRINT A, SQR(A) : RETURN
Cards: All
DESCRIPTION
GOSUB provides subroutine capability within RPBASIC-52 programs. A subroutine may be called from
within another subroutine.
GOSUB saves the location of the program statement after G OSUB on the C-Stack and im mediately transfers
program control to line number. When a RETURN is encountered, program execution resumes at program
statement after GOSUB.
GOSUB s can be nested. The number nesting is limited by available C-Stack RAM, but is usually enough for
at least 30 routines.
RELATED
GOTO, ON-GOTO, ON-GOSUB
ERROR
C-STACK An unexpected RETURN is encountered or the number of subroutines executed was excessive.
EXAMPLE
10 GOSUB 100
20 PRINT "Back from routine"
30 END
100 PRINT "In subroutine"
110 RETURN
>run
In subroutine
Back from routine
Komentáře k této Příručce