ON-GOTO
ON
JlU11/tric-eApre8SioJl 1
g~~~
~
line-number(
,line-numbcIi.
- .
The
ON-GOTO statement tells the computer
to
jump
to
one of
several program lines, depending on the value ofthe numeric-
expressIOn.
The
computer first evaluates the numeric-expression
and
rounds
the result to
an
integer.
This
integer then becomes a pointer
for
the
computer,
indicating
which
program
line in
the
ON-GOTO
statement to perform next.
If
the value of the numeric-expression is
1,
the computer will proceed to the statement with the first line-
number
specified
in
the
ON
-GOTO
statement.
If
the
value
is 2,
the
computer will branch to the statement with the second line-number
listed in the ON-GOTO statement. and so on.
If
the rounded value
of
the numeric-expression is less than 1 or
greater than the number of line-numbers listed
in
the ONĀ·GOTO
statement, the program will stop running
and
print "BAD VALUE
IN
xx,"
If
the line-number you specify is outside the range of line
numbers in your program, the message
"BAD
LINE
NUMBER" is
displayed and
the
program stops running.
II-50
Examples:
>NEW
>100
REM
HOW
DOES
ON-GoTD
WORK?
::>110
INf'UT x
>120
ON
X
GoTo
130,150,170,19
0,210
>130
PRINT
"X=1"
::>140
GOTO
110
>150
PRINT
"X=2"
>160
GOTO
110
>170
PRINT
"X;;;3"
>160
GOTO
110
>190
PRINT
"X=4"
>200
GOTo
110
>210
END
:>RUN
? 2
X=2
?
1.
2
x=1
?
3.7
x=4
? 6
*
BAD
VALUE
IN
120
User's Reference Guide