Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (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
      Read
      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
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
DATAD{Shift+A}831.0 to 7.0Command* and Statement

 
Syntax 
DATA literal [ , literal ] ...
 
ParametersTypeLegal Value(s)Default ValueNote(s)
literalNumeric or stringany except quote(") or null Strings which contain commas, semicolons, or colons must be quoted.

 
 
Purpose 
List constant values for program use.

 
 
Remarks 
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 
REM 
 
 
See Also 

© H2Obsession, 2014