Chawter
10
I
BASIC
Keywords
READ
Statement
READ
variable[,uariable,..
.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 assigned to the
first
variable; the second
time, the second value is assigned to the second variable, and
so
on.
A
single READ may access
1
or
more DATA statements, or sev-
eral READS may access the same DATA statement. If a program
contains multiple DATA statements, BASIC reads them in the
or-
der they appear.
The values read must agree with the variable types specified in
a 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(s1, BASIC returns an
“Out
of
DATA” error message. If the number
of
variables speci-
fied is less than the number of elements in the DATA state-
ment(s), the next READ statements begin reading data at the
first unread element.
To reread DATA statements from the start, use the RESTORE
statement.
Example
READ
T
reads
a
numeric value from
a
DATA statement and assigns
it
to
variable T.
286