Chapter 14. READ ... DATA ... RESTORE

These instructions provide you with a way of giving data to a program before it is run. This means that the data can be saved as part of the program (see chapter 9). The variables are placed after READ, and each is loaded in turn from the information placed after DATA.

10 FOR I = 1 TO 4
20 READ Age%,Dog$
30 PRINT "Name: ";Dog$;" Age: ";Age%
40 NEXT I
50 DATA 9,BONZO,3,ROVER
60 DATA 7
70 DATA SPOT,12,HENRY
>RUN
Name: BONZO Age: 9
Name: ROVER Age: 3
Name: SPOT Age: 7
Name: HENRY Age: 12

You can see that it doesn't matter how many DATA instructions are used provided the types of data match the variable.

RESTORE is used to set the data-pointer to the start of the DATA, in this case line 50. It can also be used to set the data-pointer to any line number:

10 INPUT "Which dog (1 to 4) ",A
20 RESTORE (A4)*10
30 READ Age%,Dog$
40 PRINT"NAME: ";Dog$;" Age: ";Age%
50 DATA 9,BONZO
60 DATA 3,ROVER
70 DATA 7,SPOT
80 DATA 12,HENRY
>RUN
Which dog (1 to 4)?2
NOM: ROVER Age: 3