BASIC READ Statement - fvdhoef/aquarius-plus GitHub Wiki

READ

TYPE: BASIC I/O Statement

FORMAT: READ variable[,variable]...

Action:

The READ statement is used to fill variable names from constants in DATA statements. The data actually read must agree with the variable types specified or the BASIC message ?SN error will result. Variables in the DATA input-list must be separated by commas.

A single READ statement can access one or more DATA statements, which will be accessed in order (see DATA, or several READ statements can access the same DATA statement. If more READ statements are executed than the number of elements in DATA statements(s) in the program, the BASIC message ?OD error is printed. If the number of variables specified is fewer than the number of elements in the DATA statement(s), subsequent READ statements will continue reading at the next data element. (See RESTORE.)

⚠️ Note: The ?SN error will appear with the line number from the DATA statement, NOT the READ statement.

EXAMPLES of READ Statement:

110 READ A,B,C$
120 DATA 1,2,HELLO
100 FOR X=1 TO 10: READ A(X):NEXT
 
200 DATA 3.08, 5.19, 3.12, 3.98, 4.24
210 DATA 5.08, 5.55, 4.00, 3.16, 3.37

Fills array items (line 1) in order of constants shown (line 5) :

1 READ CITY$,STATE$,ZIP
5 DATA DENVER,COLORADO, 80211

FORMAT: READ * _array

Action: Fills an array from the contents of DATA statements.

Examples:
100 DIM N$(9)
120 READ *N$
130 DATA zero,one,two,three
140 DATA four,five,six
150 DATA seven,eight,nine
160 FOR I=0 TO 9
170 PRINT I;" ";N$(I)
180 NEXT I

Under the Hood:

The BASIC interpreter uses common code to execute READ and INPUT. During an INPUT, memory location 14541 contains 0, and the input buffer is scanned. During a READ, memory location 14541 contains 239, and the DATA lines in the BASIC program are scanned. In between READs, the address of the next byte to scan is stores in locations 14556 and 14557.


⚠️ **GitHub.com Fallback** ⚠️