<!-- PDF page 36 -->

first **DATA** statement at or after the given line number. (You can miss out the line number, in which case it is as though you had typed the line number of the first line in the program.)

Try this program:

```
10 READ a,b
20 PRINT a,b
30 RESTORE 10
40 READ x,y,z
50 PRINT x,y,z
60 DATA 1,2,3
70 STOP
```

In this program the data required by line 10 made **a**=**1** and **b**=**2**. The **RESTORE 10** instruction allowed **x**, **y** and **z** to be **READ** starting from the first number in the **DATA** statement. **RUN** this program again, without line 30 and see what happens.

> **Notes**
>
> You can store **DATA** statements in memory banks to take advantage of the expanded memory available on the ZX Spectrum Next. Refer to *Chapter 23 – The Memory*, for information on how to use **BANK RESTORE** to do this.
>
> **READ**, **DATA** and **RESTORE** accept integer variables following the conventions set forth in *Chapter 6 – Expressions*.

### DATA (function)

Apart from its use in subroutines as we saw in the previous chapter, **DATA** can also be used as a *function* that returns what the next *DATA* item to be read is; Return values can be: *numeric* (**1**), *string* (**2**) or *none* (**0**) – when there are no more data items available. This is most useful if we want to load a list of items with varying data types. Consider this example:

```
10 @rd:ON DATA:GO TO @prn:
   READ number: READ text$:
   ELSE GO TO @rd
20 GO TO @rd
30 @prn: PRINT text$;number
40 DATA 3,"Here we come KS"
```

What have we done here? We've used the handy **ON...ELSE** *conditional selection* structure and placed the **DATA** *function* in lieu of a variable argument since it returns one of 3 values. Then used the data type look ahead that **DATA** as a function provides to decide whether our next **READ** operation will be a numeric or string one (As **ON** expects its statements according to an increasing order of values, the *exit condition* is first).

Note that **ELSE** is really redundant here as there are 3 possible values of **DATA** and all are covered by the statements available, however it was put there as an additional demonstration of the complete **ON...ELSE** structure.

