Radio Shack TRS-80 PC-3 Owner's Manual page 134

Table of Contents

Advertisement

1 GOSUB expression
Abbreviations: GOS., GOSUB.
See also: GOTO, ON ... GOSUB, ON ... GOTO, RETURN
Purpose
The GOSUB verb is used to execute a BASIC subroutine.
Use
When you wish to execute the same group of statments several time in the course of a program, or use a previously written set of
statements in several programs, it is convenient to use the BASIC capability for subroutines using the GOSUB and RETURN verbs.
The group of statements is included in the program at some location where they are not reached in the normal sequence of execu-
tion. A frequent location is following the END statement which marks the end of the main program. At those locations in the
main body of the program, where subroutines are to be executed, include a GOSUB statement with an expression which indicates
the starting line number of the subroutine. The last line of the subroutine must be a RETURN. When GOSUB is executed, the
PC-3 Pocket Computer transfers control to the indicated line number and processes the statements until a RETURN is reached.
Control is then transferred back to the statement following the GOSUB.
A subroutine may include a GOSUB. Subroutines may be "nested" in this fashion up to 10 levels deep.
The expression in a GOSUB statement may not include a comma, e.g., 'A(1,2)' cannot be used. Since there is an ON ... GOSUB
structure for choosing different subroutines at given locations in the program, the expression usually consists of just the desired line
134

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents