On ... Goto

On expression GoTo label1[, label2[, ..., [labelN...]]]

The statement On-GoTo sends the program flow to one of several possible destinations based on the value of a integer expression in the range of 0 - 231.

Example 1:

Init:

Print "0) Exit Menu"
Print "1) Pizza"
Print "2) Pasta"

Input "Your preference"; p%

If p%<0 or p%>2 Then GoTo Init

On p% GoTo quit, pizza, pasta

pizza: Print "ONE PIZZA FOR YOU" : GoTo quit
pasta: Print "PASTA !!!" : GoTo quit

quit: End

Example 2:

' graph.bas - This file is part of nuBASIC
dx%=GetSWidth()
dy%=GetSHeight()
Init:
x1%=Rnd(1)*dx%
x2%=Rnd(1)*dx%
y1%=Rnd(1)*dy%
y2%=Rnd(1)*dy%
t%=Int(Rnd(1)*6)
c%=Int(Rnd(1)*&hffffff)
On t% Goto _line, _rect, _frect, _ell, _fell, _text, skip
_line: Line x1%,y1%,x2%,y2%,c% : Goto skip
_rect: Rect x1%,y1%,x2%,y2%,c% : Goto skip
_frect: FillRect x1%,y1%,x2%,y2%,c% : Goto skip
_ell: Ellipse x1%,y1%,x2%,y2%,c% : Goto skip
_fell: FillEllipse x1%,y1%,x2%,y2%,c% : Goto skip
_text: TextOut x1%,y1%, "nuBASIC",c% : Goto skip
skip:
k$=InKey$()
If k$="q" Then End
Goto Init
Comments