on goto - branch based on expression


on NumExpr goto LineNum[, LineNum] . . . 
on NumExpr goto LineLab[, LineLab] . . . 


The on goto statement transfers control to one of several program locations based on the value of a numerical index, supplied by the NumExpr argument.  NumExpr must be a numeric value and if it is not an integer, it is rounded to integer before use as the index.  The LineNum and LineLab arguments are assumed to be valid line numbers in the program.  LineNum and LineLab arguments may be mixed in the same statement.  The value of the index selects a LineNum or LineLab argument to which to transfer control based on direct correspondence between the index value and the position of the arguments in the list.  An index value of 1 selects the first argument, 2 the second, and so on. 

If the value of NumExpr is zero or greater than the number of items in the list, no transfer occurs and BASIC continues with the next executable statement. 


The program below branches to line 100 if x equals 1, to line 200 if x equals 2, to line 300 if x equals 3, and to line 400 if x equals 4.  If x is equal to 0 (zero) or is greater than 4, then the program just goes on to the next statement. 
	    a = 1
	    on x goto 100, 200, 300, 400
	900 end


gosub, goto, on gosub


If NumExpr is negative, an "Illegal function call" error occurs. 

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber