ON...GOSUB/ON...GOTO¶
Syntax¶
Versions: 8K, Extended, Disk
Purpose¶
To branch to one of several specified line numbers, depending on the value returned when an expression is evaluated.
Remarks¶
The value of <expression> determines which line number in the list will be used for branching. For example, if the value is three, the third line number in the list will be the destination of the branch. (If the value is a non-integer, the fractional portion is rounded.)
In the ON...GOSUB statement, each line number in the list must be the first line number of a subroutine.
If the value of <expression> is zero or greater than the number of items in the list (but less than or equal to 255), BASIC continues with the next executable statement. If the value of <expression> is negative or greater than 255, an "Illegal function call" error occurs.
Example¶
See Also¶
- FOR...NEXT - Execute statements repeatedly with a loop counter
- GOSUB...RETURN - Branch to and return from a subroutine
- GOTO - Branch unconditionally to a specified line number
- IF...THEN...ELSE - Make decisions and control program flow based on conditional expressions
- WHILE...WEND - Execute statements in a loop while a condition is true