in BASIC ROM:
|List of all BASIC keywords|
Typ: Command General Programming-Syntax: READ <variable> [,<variable>]...
The BASIC command READ is used for reading constant values from DATA lines into the indicated variables. This command is able to read more constants at once with a variable list separated by commas.
If using the wrong type of variable (for example read a character string into a numerical variable like float or integer) the BASIC error ?SYNTAX ERROR IN line occurs with a reference of the corresponding DATA line. Starting with BASIC 3.5 the error message changes to ?TYPE MISMATCH ERROR and the line number points directly to the READ statement that triggered the condition. Such behavior can be prevented by generally using string variables.
With a value that falls outside the expected range of a READ variable, e.g. the value is outside the range of an integer, BASIC breaks with error ?ILLEGAL QUANTITY ERROR.
If more constants are read than values exist in DATA lines the BASIC error ?OUT OF DATA appears.
The BASIC command RESTORE resets the current DATA read pointer to beginning of the program. A succeeding READ searches for the first DATA statement where the DATA read pointer is adjusted to. How long a READ takes depends on how many program lines are to be processed to advance the DATA read pointer to the next DATA line. See DATA for an advice where to place DATA lines.
Read in different data types
10 DATA 1,2,3, APPLE, "COMMODORE 64", ."DOUBLE-QUOTES", "WITH,COMMA" 20 READ A 30 READ B%, C, D$ 40 READ E$ 50 READ F$, G$ 60 PRINT A, B%, C, D$, E$, F$, G$
Characters like space, double quotes, comma, colon are handled correctly, giving following output:
1 2 3 APPLE COMMODORE 64 ."DOUBLE-QUOTES" WITH,COMMA
Get values by means of a loop