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


Keyword Abbreviation Token (hex) Version(s) Classification
DATA D{Shift+A} 83 1.0 to 7.0 Command* and Statement

DATA literal [ , literal ] ...
Parameters Type Legal Value(s) Default Value Note(s)
literal Numeric or string any except quote(") or null   Strings which contain commas, semicolons, or colons must be quoted.

List constant values for program use.

This statement allows a set of numbers and/or strings to be simply entered into a program.  DATA doesn't do anything by itself; in fact it essentially acts like REM.  Unlike REM (which ignores everyting else on the line), any statement(s) following DATA on the same line will be processed normally.  For this reason, a text string which contains a colon (used to seperate BASIC statements) must be in enclosed in quotation marks (").  Similarly, because items in the list are seperated by commas, any text string that should contain a comma must likewise be enclosed in quotation marks.
Any leading spaces before the literal value are ignored, unless the value is quoted.  So DATA 1, HELLO would be the same as DATA 1,HELLO.  Thus use DATA 1, " HELLO" if you want the leading space(s).  On the other hand, trailing spaces are included if more literal value(s) or statements follow.  So DATA HELLO, 1 would be different than DATA HELLO , 1.
There is no way to actually specify a quotation mark as a literal character or as part of a string.  There is no way to specify ASCII NUL as part of a string, but an empty string (often interpretted as ASCII NUL) may specified by completely eliminating a literal (or using only space(s)).  For example, DATA ,1 would be interpretted as the two values "empty string" and one.
Numeric values are normally not quoted, but they might be.  If so, they will be interpreted as strings and not numeric values when they are later read by the program.  Numeric values must be literal values; they can not (generally) be mathematical expressions.  Most mathematical expressions would be interpretted as a string.  An exception is simple negation/positivation; so -1 and +1 would each be considered a number.  But 1-1 (for example) would be a string.
The text comprising the literal values is never tokenized.  Doing so might make some programs shorter, but the need to un-tokenize them when the program runs would slow things down and make the BASIC interpreter more complex. 
DATA is typically used when a series of related values are needed.  For example, the default values of an array, or a sequence of bytes to be POKE'd into RAM.
* DATA may be entered as a command in direct mode, but it has no effect because the literal value(s) are not stored in the program.
Compare With  
See Also  

© H2Obsession, 2014