Specifications
Chapter 14. Statement Reference
258
Syntax:
Syntax 1:
ON expression GOSUB label [,label...]
Syntax 2:
ON expression GOTO label [,label...]
Parameter:
expression
A numeric expression which returns a value from 1 to 255.
Description:
ON...GOSUB or ON...GOTO block branches to a label in the label list according to
the value of expression.
• If
expression has the value 3, for example, the target label is the third one in
the label list counting from the first.
• If
expression has the value 0 or a value greater than the number of labels in
the label list, execution of the ON...GOSUB or ON...GOTO block causes no run-
time error and passes control to the subsequent statement.
• You can specify any number of labels so long as a statement block does not
exceed one program line (512 characters).
• You can nest
ON...GOSUB statements to a maximum of 10 levels.
• When using the
GOSUB statement together with block-structured statements
(DEF FN...END DEF, FOR...NEXT, FUNCTION...END FUNCTION, IF...THEN
...ELSE...END
IF, SELECT...CASE...END SELECT, SUB...END SUB and
WHILE...WEND), you can nest them to a maximum of 30 levels.
• You can use
ON...GO TO instead of ON...GOTO.
Flow control statement
ON...GOSUB and ON...GOTO
Branches to one of specified labels according to the value of an expression.