ON GOTO/GOSUB Verbs

Syntax

ON int GOTO lineref{,lineref...}
ON int GOSUB lineref{,lineref...}

Description

The ON statement provides a GOTO or a GOSUB with several possible branch destinations.

Parameter Description
int Branch destination. If int is zero or negative, the first lineref in the list becomes the destination of the branch. If int is 1, then the second lineref is used, and so forth. If int is larger than the number of lineref options, the last lineref is used. If int does not evaluate to an integer value, !ERROR=41 is generated.
lineref Branch destination line number.

For example, if the code states the following and the value of A is 6, the program branches to line 5000.

2010 ON A GOTO 3000,4000,5000

The GOTO or GOSUB statements are executed exactly like normal GOTO or GOSUB statements, and the same line number can appear more than once in the list. However, ON GOSUB cannot be used in console mode. In a compound statement, only ELSE, FI, or REM can follow ON GOTO.

Examples

1000 ON A GOTO 1100,1200,1300
1000 ON B GOSUB 2100,2200,2200,2300

See Also

Verbs - Alphabetical Listing