A DATA statement is a list of expressions, & taking all the DATA statements in the program gives one
long list of expressions, the DATA list.
READ statements are used to assign these expressions, one by one, to variables:
READ X
for instance, assigns the current expression in the DATA list to the variable X, & moves on to the next
expression for the next READ statement.
[RESTORE moves back to the beginning of the DATA list.]
In theory, you can always replace READ & DATA statements by
LET
statements; however, one of their
major uses is in initializing arrays, as in this program:
5
REM
THIS PROGRAM WILL NOT WORK IN ZX81 BASIC
10
DIM
M$(12,3)
20
FOR
N=1
TO
12
30
READ
M$(N)
40
NEXT
N
50
DATA
"JAN","FEB","MAR","APR"
60
DATA
"MAY","JUN","JUL","AUG"
70
DATA
"SEP","OCT","NOV","DEC"
If you only want to run this program once, you might as well replace line 30 with an
INPUT
statement
thus:
10
DIM
M$(12,3)
20
FOR
N=1
TO
12
30
INPUT
M$(N)
40
NEXT
N
& you will have no extra typing to do. However, if you want to save the program, you will certainly not want
to type the months in every time you
run it.
We suggest that you use this method:
(i) Initialize the array using a program like the one above.
(ii) Edit out the initialization program. (Don't use
NEW
, because you want to preserve the array.)
(iii) Type in the rest of the program, & save it. This will save the variables as well, including the array.
(iv) When you load the program back, you will also load the array.
(v) When you execute the program, do not use
RUN
, which clears the variables. Use
GOTO
with a line
number instead.
You may alternatively be able to use the
LOAD
& execute technique of chapter 16, & its exercise 3.
Then in stage (iii) above you will use a
SAVE
statement in the program, & stage (v) will be omitted
altogether.