READ
I READ variable,
....
Statement
I
Reads values from a DATA statement and assigns them to variables.
BASIC assigns values from the DATA statement
on
a one-to-one
basis. The first time READ
is
executed, the first value
in
the first
DATA statement
is
used; the second time, the second value is used,
and
so
on.
A single READ may access one or more DATA statements (each
DATA statement
is
accessed
in
order), or several READs may access
the same DATA statement.
The values read must agree with the variable types specified
in
list of
variables, otherwise, a "Syntax error" occurs.
If
the number of
variables
in
the READ statement exceeds the number of elements
in
the DATA statement(s),
an
"Out of data" error message is printed.
If the number of variables specified
is
lower than the number of
elements
in
the DATA statement(s), subsequent READ statements
begin reading data at the first unread element.
Example
READ T
reads a numeric value from a DATA statement and assigns it to
variable
"T".
Sample Program
This program illustrates a common application for the READ and
DATA statements.
40
PRINT
"NAME",
"AGE"
50
READ N$
60
IF
N$="END"
THEN
PRINT
"END
OF
LIST":
END
70
READ
AGE
80
IF
AGE<18
THEN
PRINT
N$,
AGE
80
GoTD
50
100
DATA
"SMITH,
JOHN",
30,
"ANDERS,
T.M."·,
20
110
DATA
"JONES,
BILL",
15,
"DOE,
SALLY",
21
120
DATA
"COLLINS,
W.P.",
17,
"END"
2-149