EasyManua.ls Logo

Radio Shack TRS-80 - Chapter 16: Reading Data; DATA and READ Statements

Radio Shack TRS-80
236 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...
Chapter
16
READing
DATA
So far,
we
have
learned how to
enter numbers into our
programs
by
two
different methods.
The first
is by
building
the value into the
program
:
10
A
=
5
The second
is by using
an
INPUT statement to enter a
number through the keyboard:
10
INPUT
A
The
third
principal
way
is through
the
DATA statement.
Enter this
program
:
10
DATA 1,2,3,4,5
20
READ
A ,B ,C ,D
,E
30
PRINT
AiBiC|D;E
. . . and RUN.
The
DATA
statement is
in some
ways
similar to the
first method
in that
a
DATA line is
part
of
the
program. It's
different,
however,
since each
DATA
line can
contain
many num-
bers, or
pieces of
data, each
separated by a
comma. Each
piece of DATA must be read by a
READ statement.
Each READ
statement
can read a
number of
pieces
of
DATA if each
variable
letter is separated
by
a
comma.
The
display
shows
that
all 5
pieces
of
data in line
10,
the numbers
1, 2, 3,
4
and
5
were
READ by
line
20,
assigned
the
letters
A
through E, and
printed by line
30.
j^pih
mind this important
distinction: DATA lines
can
he read only by READ
state-
ments. If
more
than one
piece
of
data is
placed on a DATA
liney
they must
be
Separated
by commas.
Keyboard
data
can
be
entered
only
via
INPUT
statements.
DATA lines are
always
read
from
left to right by READ
statements; the first DATA
line
first (when there is more
than
one),
and IT DOES NOT
MATTER WHERE
THEY
ARE IN
85

Other manuals for Radio Shack TRS-80

Related product manuals