EasyManua.ls Logo

Radio Shack TRS-80 Model III - Page 164

Radio Shack TRS-80 Model III
274 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
TRS-80
MODEL
ON n
GOTO line number,
...,
line number
This is
a
multi-way
branching
statement that is controlled
by
a
test variable
or
expression.
The general format
for ON
n
GOTO is:
ON
expression
GOTO 1st line number,
2nd
line
number,
. .
.,
Kth line
number-
expression must
be between and
255 inclusive.
When ON.
. .
GOTO is executed, first
the expression
is evaluated
and the integer
portion.
. .
INT(expression).
. .
is obtained.
We'll referto
this integer
portion
as J.
The Computer
counts over
to the Jth element
in the line-number
list, and
then
branches
to the line number
specified
by that element. If
there is no
Jth element
(that is, if
J
>
K or
J
=
in
the general
format above),
then control
passes to
the next
statement
in the program.
If the
test expression
or number is
less than
zero, or greater
than
255, an error will
occur. The line-number
list
may contain
any number
of items.
For
example:
100 ON
Ml GOT0
150, 160,
170,150,
180
says "Evaluate
MI. If integer
portion
of MI equals
1 then
go
to
line
150;
If it
equals
2
,
then
go
to 1
60;
If it
equals
3,
then
go
to
170;
If
it equals
4,
then
go
to
150;
If it
equals
5
, then
go
to
1
80;
If
the integer
portion
of MI doesn't
equal any of
the numbers
1 through
5,
advance to the
next
statement in
the program.
'
'
Sample
Program
100 INPUT
"ENTER A
NUMBER";
X
110 ON SGN(X)
+
2 GOTO
200 i 210,
220
200 PRINT
"NEGATIVE":
END
210 PRINT
"ZERO": END
220 P R I NT "
POS I
T I
VE
"
:
END
SGN(X)
returns
-
1
for
X
less
than zero;
for
X
equal
to zero; and
+ 1 for
X greater
than
.
By
adding
2
,
the
expression
takes on the values
1,2,
and
3
, depending
on
whether
X is negative,
zero, or positive.
Control
then branches
to
the
appropriate
line
number.
154

Other manuals for Radio Shack TRS-80 Model III

Related product manuals