Chapter
10
I
BASIC Keywords
ON/GOTO
Statement
ON
n
GOTO
line[,line,
...
I
Looks
at
n
and transfers program control
to
the nth line listed.
For example, if
n
equals
1,
BASIC branches to the first line
listed; if
n
equals
2,
BASIC branches
to
the second line listed.
N
must be in the range
0
to
255.
If necessary, BASIC rounds
n
to
an integer before evaluating it. If
n
is
0
or
is greater than the
number
of
line numbers listed, BASIC continues with the next
statement. If
n
is
negative
or
is greater than
255,
an "Illegal
function call" error occurs.
Example
10 ON MI GOTO 150, 160, 170, 150, 180
tells BASIC
to
evaluate MI. If MI equals
1,
BASIC branches to
Line
150;
if MI equals
2,
BASIC branches
to
Line
160;
and
so
on. If MI
is
outside
of
the range
1
to
5,
BASIC either continues
with the next statement or generates an Illegal function call,
as
mentioned earlier.
Sample Program
5
REM <CAPS> MUST BE ON
10 INPUT "ENTER
A,B,
or
C,";LS
20 L=CISC
CLS)
30
ON
L-64 GOTO 50, 60, 70
40 PRINT "TRY AGCI1N":GOTO 10
60
PRINT
"YOU
TYPED 'B'":END
70 PRINT "YOU
TYPED 'C'":END
50
PRINT
91~0~
TYPED
'A'~~:END
231