Home > CBM > BASIC > Keywords > Read
180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor

KeywordAbbreviationToken (hex)Version(s)Classification
READR{Shift+E}871.0 to 3.5Command and Statement
READRE{Shift+A}87 4.0 to 7.0Command and Statement 

 
Syntax 
READ variable [ , variable ] ...
 
ParametersTypeLegal Value(s)Default ValueNote(s)
variableString or numericany except reserved variableType 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

READY.
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