Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

READ

Keyword Abbreviation Token (hex) Version(s) Classification
READ R{Shift+E} 87 1.0 to 3.5 Command and Statement
READ RE{Shift+A} 87  4.0 to 7.0 Command and Statement 

 
Syntax  
READ variable [ , variable ] ...
 
Parameters Type Legal Value(s) Default Value Note(s)
variable String or numeric any except reserved variable Type must be valid for the data that is read

 
 
Purpose  
Variable initialization.  Get a value from a DATA statement and store it in a variable; perhaps multiple times.

 
 
Remarks  
This statement reads one or more values from DATA statements in the program and stores it (them) into the specified variable(s).  Each datum read must be compatible with each variable's type.  So a string variable must be specified if text is to be read.  A numeric variable is typically used to read numeric values, but a string variable can hold a number if desired.  If the DATA being read is not valid for the variable's type, then a TYPE MISMATCH ERROR occurs.

A "null value" will be interpreted as either a zero (numeric variable) or an empty string (string variable).

Strings stored in DATA statements do not need to be quoted, unless they contain a colon (:) or a comma (,).  A string may never contain a double-quote character (") or a carriage return (ASCII 13).
 
Whenever CLR is executed (automically when a program is RUN), a secret DATA pointer is set to the beginning of the program.  Whenever a READ is executed the DATA item is stored in the specified variable, and then the secret  pointer is advanced to the next item of DATA.   This pointer can not be read by the programmer (which is why it is called a secret), but it can be changed with RESTORE.
 
If more variable(s) are requested than remain in the DATA statement(s) of the program, an OUT OF DATA ERROR is generated.
 
READ is useful to initialize array(s) with constant data, or POKE memory with specific bytes.  Other creative uses are possible.
 
Although READ operates very similar to INPUT, one notable difference is that READ may be used as a command in direct mode.  This "feature" does not seem very useful.
 
Example:
NEW
10 DATA SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
20 FOR I = 1 TO 7
30 READ D$(I) : NEXT
40 PRINT D$(6)
RUN
FRIDAY

READY.
 
 
  Compare With  
 
  Contrast With  
 
  See Also  
CLR, DATA, RESTORE  
© H2Obsession, 2014
Comments