ON GOSUB
Conditional GOSUB
This directive unconditionally branches to one of a series of program line number or labels, depending on the value of a numeric expression, and remembers where it came from to allow the program to come back with a RETURN directive.
Syntax
Section titled “Syntax”ON numeric-value GOSUB line-ref0 [,line-ref1 [,line-ref2...line-ref-n]]numeric-value- is an integer.
line-ref0- is the program line number or label to branch to if numeric-value is less than 1 (negative or 0).
line-ref1- is the program line number or label to branch to if numeric-value is equal to 1.
line-ref2- is the program line number or label to branch to if numeric-value is equal to 2.
line-ref-n- is the program line number or label to branch to if numeric-value is equal to or greater than n.
Remarks
Section titled “Remarks”The combination of ON/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 function or action, and return to the specific point, which referenced their execution.
Program execution resumes at the statement following the ON/GOSUB directive when a RETURN directive is executed.
This directive cannot be used in Thoroughbred Basic Console Mode.
If numeric-value is not an integer, an ERR=41 results.
The first line-ref listed is targeted if numeric-value is 0 or less, the second line-ref is targeted if numeric-value is 1, and so on with the last line-ref targeted for all remaining values of numeric-value.
Examples
Section titled “Examples”ON DECISION GOSUB 100,200,300If DECISION = -2 then execute statement 100.
If DECISION = 0 then execute statement 100.
If DECISION = 1 then execute statement 200.
If DECISION = 2 then execute statement 300.
If DECISION > 2 then execute statement 300.
ON ERR (16, 32, 33) GOSUB 08000, 08100, 08200, 08300branches to a routine beginning at 08100 if ERR=16.
branches to a routine beginning at 08200 if ERR=32.
branches to a routine beginning at 08300 if ERR=33.
branches to a routine beginning at 08000 for all other values of ERR.
See also
Section titled “See also”EXITTO, GOSUB, and RETURN directives
From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF