35
ON … GOSUB …
Purpose To call one of the sev
eral specified subroutines depending on the value of the
expression.
Syntax ON N GOSUB SubName|SubLabel {, SubName|SubLabel}
Remarks “N” is a numeric expression that is rounded to an integer. The value of N
determines which subroutine is to be called. If the value of N
is 0, or greater
than the number of routines listed, the interpreter will continue with the next
executable statement.
“SubName” is the name of a subroutine.
“SubLabel” is the line label of a subroutine.
Example
PRINT “Input a number (1-9):”
INPUT Num%
CLS
ON Num% GOSUB 100, 100, 100, 200, 200, 300, 400, 400, 400
…
100
PRINT “Number 1-3 is input.”
RETURN
200
PRINT “Number 4-5 is input.”
RETURN
300
PRINT “6 is input.”
RETURN
400
PRINT “Number 7-9 is input.”
RETURN