2. 3. 6. 7
ON~GOTO
. .
.. ..
.........
. . .
........
. . . (abbreviated format:
ON~G.)
Format
Function
Example
ON e GOTO
Lr
1
<::
,
Lr
2
,
Lr
3
,
. •
..
. , Lri >
e
..
. Numeric variable, array element,
or
expression
Lri . List
of
destination line numbers
This statement branches execution
to
one
of
the
line numbers following GOTO,
depending
on
the
value
of
e.
The
value
of
e indicates which
of
the
line
numbers
following GOTO is
to
be
used
for
making
the
branch; in
other
words,
if
e
is
1,
execution branches
to
the
-first
line
number
in
the
list;
if
e is 2,
execution
branches
to
the
second line
number
in the list; and so forth.
For
example:
1
00
ON A GOTO
200
,
300
. 4
00
. 5
00
Destinatio:
:h~
_
n
______
J
__
____,j
1
A
is
2 -
Ais3-
----------~
Ais4
-----------
---
--~
10
I N
PUT
" NUMB
ER
" ; A
20
ON A
GO
TO
50
.
60.
7 0
50
PRINT
"XXX"
: GO TO 1 0
60
PRI
NT "YYY "
: GO TO
10
70
PR
I NT " Z
ZZ
"
:GO
TO
10
RUN
If a dec
im
al
nu
mb
er
such as 1 .
2
is
NUMBE R 9 1
specif ied, t he dec
imal
port
i
on
is t runca
ted
XXX
bef
ore
evaluating the
statement.
NU
MBE R 9
2
yyy
NUMBER 9
~
Note When
the
value
of
e in an
ON~GOTO
statement
is greater
than
the
number
of
line numbers specified following GOTO, execution continues
with
the
next
line
of
the program.
This also applies
if
the value
of
e is less
than
1
or
negative.
Further
,
if
the
value
of
e is a
non
-integer,
the
decimal
portion
is
truncated
to
obtain
an integer value before
the
statement
is evaluated.
64------
----------------------------------
--
----------
--
----------
---