FORMAT: ON <variable> GOTO / GOSUB
Action: The ON statement is used to GOTO
one of several given line-numbers, depending upon the value of
a variable. The value of the variables can range from zero through
the number of lines given. if the value is a non-integer, the
fractional portion is left off. For example, if the variable value
is 3, ON will GOTO the third line-number
in the list.
If the value of the variable is negative, the BASIC error message
?ILLEGAL QUANTITY occurs. If the number is zero, or greater than
the number of items in the list, the program just "ignores"
the statement and continues with the statement following the ON
ON is really an underused variant of the IF...THEN...statement.
Instead of using a whole lot of IF statements each of which sends
the program to 1 specific line, 1 ON statement can replace a list
of IF statements. When you look at the first example you should
notice that the 1 ON statement replaces 4 IF...THEN... statements.
EXAMPLES of ON Statement:
ON -(A=7)-2*(A=3)-3*(A<3)-4*(A>7)GOTO 400,900,1000,100
ON X GOTO 100,130,180,220
ON X+3 GOSUB 9000,20,9000
100 ON NUM GOTO 150,300,320,390
500 ON SUM/2 + 1 GOSUB 50,80,20