GOSUB
Branch to Subroutine
This directive unconditionally branches to a statement number but remembers where it came from to allow the program to come back with a RETURN directive.
Syntax
Section titled “Syntax”GOSUB line-refline-ref- is the program line number or label to branch to.
Remarks
Section titled “Remarks”The combination of GOSUB and RETURN directives provides the ability to use subroutines in a program, which can be executed from several places within the overall program, perform a predetermined action, and return to the specific point, which referenced their execution.
Program execution resumes at the statement following the GOSUB directive when a
RETURN directive is executed.
Subroutines can be nested by placing a GOSUB directive in another subroutine, but the nested subroutines must have properly organized endings or exits to avoid errors.
To avoid possible execution errors, a subroutine should be terminated with a RETURN directive. An EXITTO directive should be used only if it is necessary to interrupt the subroutine operation and disregard the point in the program that issued the GOSUB.
This directive cannot be used in Thoroughbred Basic Console Mode.
Examples
Section titled “Examples”GOSUB 08976causes the program to start execution of the subroutine at statement number 8976; a
RETURN directive will return execution to the statement following the GOSUB directive.
IF X = 8 THEN GOSUB 8976The placement of the GOSUB directive in an IF directive has the same effect as the first example, but is only executed if X=8
See also
Section titled “See also”EXITTO, ON GOSUB, and RETURN directives
From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF