QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The READ statement reads values from a DATA field and assigns them to one or a comma separated list of variables.

Syntax

READ value1$[, value2!, value3%, …]

Example(s)

Placing data into an array.


DIM A(10) AS SINGLE
FOR I = 1 TO 10
   READ A(I)
NEXT I
FOR J = 1 TO 10
   PRINT A(J);
NEXT
END

DATA 3.08, 5.19, 3.12, 3.98, 4.24
DATA 5.08, 5.55, 4.00, 3.16, 3.37 


 3.08  5.19  3.12  3.98  4.24  5.08  5.55  4  3.16  3.37

Explanation: This program reads the values from the DATA statements into array A. After execution, the value of A(1) is 3.08, and so on. The DATA statements may be placed anywhere in the program; they may even be placed ahead of the READ statement.

Reading three pieces of data at once.


 PRINT " CITY ", " STATE  ", " ZIP"
 PRINT STRING$(30, "-")  'divider
   READ C$, S$, Z&
 PRINT C$, S$, Z&

 DATA "DENVER,", COLORADO, 80211 


  CITY        STATE       ZIP
 ------------------------------
 DENVER,     COLORADO     80211

Note: String DATA values do not require quotes unless they contain commas, end spaces or QBasic keywords.

See Also