QBasic 1.1: ON...GOSUB Statement
Explanation
ON...GOSUB, ON...GOTO Statements
Branch to one of several locations, depending on the value of an expression.
Worth knowing
Useful and cross-version information about the programming environments of QBasic, QuickBasic and Visual Basic for DOS.
Syntax
ON expression% GOSUB line-list |
ON expression% GOTO line-list |
Description / Parameter(s)
expression% |
An expression in the range 0 through 255. |
line-list |
A set of labels or line numbers. If the value of the expression is 1, the program branches to the first line in the list; if the expression is 2, it branches to the second line, and so on. |
SELECT CASE provides a better way to perform multiple branching. |
Example
FOR i% = 1 TO 2
ON i% GOSUB One, Two
NEXT i%
END
One: PRINT "One"
RETURN
Two: PRINT "Two"
RETURN