The ON...GOSUB and ON...GOTO statements are used to transfer program execution to a label based upon a calculation.



ON expression GOTO label{, label...}
ON expression GOSUB label{, label...}


expression should evaluate to an integer numeric value. Labels should be defined somewhere in the current source file.

ON GOTO will transfer execution to the labeled source code line in the program.

ON GOSUB will transfer execution to the labeled subroutine within the source code.



The value of expression is used as an index to the list of labels supplied. If the expression evaluates to 1 then the first label will be jumped to, 2 then the second label will be used and so on.

If the program was compiled when the emulation included the setting generic_pick = true, then no validations are performed on the index to see if it is valid. Therefore if the index is out of range this instruction will take no action and report no error.

If the program was compiled for other emulations then the index will be range checked. If the index is found to be less than 1 it is assumed to be 1 and a warning message is issued. If the index is found to be too big, then the last label in the list will be used to transfer execution and a warning message issued.



INPUT Ans,1_
ON SEQ(Ans)-SEQ(A)+1 GOSUB RoutineA, RoutineB...