DATA

BASin

DATA

Statement

DATA provides a list of items of data within a program. These items may be values or variables or strings to be displayed, for example. Each item is assigned to a variable by a READ statement.

Assignment is carried out in the order in which items of data appear in the program, but RESTORE can be used to begin assignment at the first DATA item on or following a program line.

How to use DATA

DATA can only be used to form a statement in a program. It is normally followed by a list of numeric or string contants each separated by a comma, for example

50 DATA 31,"JAN",28,"FEB"

Each constant is then assigned to a variable by a READ statement that reads the DATA. The DATA statement may be positioned anywhere in the program. The number, kind (numeric or string) and order of the constants must correspond to the number of times the READ statement is executed and the kind and order of variables in the READ statement. The list of data may be split up into several DATA statements if there are too many items to fit into one statement.

Example

The following program

10 FOR n=1 TO 2
20 READ x,a$
30 PRINT a$,x;" days"
40 NEXT n
50 DATA 31,"JAN",28,"FEB"

displays

JAN               31 days
FEB 28 days

Using DATA with variables

The items of data in a DATA statement may consist of numeric or string variables or expressions provided the variables have previously been assigned values. In the above example, the DATA statement may be changed to

50 DATA d,m$,d-3,"FEB"

If d is previously assigned a value of 31, and m$ a value of "JAN", then the same display is given.

LOAD DATA, SAVE DATA, and VERIFY DATA

DATA may also be used with LOAD, SAVE and VERIFY to store arrays on tape. See LOAD DATA, SAVE DATA and VERIFY for more information.

Format

  • DATA num-expr, [num-expr][, string-expr]
  • DATA string-expr, [num-expr][, string-expr]

See also

Chapter 6.