Available on: all targets ✓ verified

DATA

The DATA command is used to store constant information in the program code, and is used with the BASIC-command READ. Each DATA-line can contain one or more constants separated by commas. Expressions containing variables will not be evaluated here.

The instruction stores numeric data in an optimized way: so, if you enter a numeric constant that can be represented by a single byte, it will be stored in the program as a single byte. Floating point numbers are stored with default precision. Finally, strings are stored "as is". As a result, when you use the READ command, ugBASIC will implicitly perform the conversion if the same data type is not used, and it is posssible. It is possible to avoid optimization by using the AS keyword with the data type.

The DATA values will be read from left to right, beginning with the first line containing a DATA statement. Each time a READ instruction is executed the saved DATA position of the last READ is advanced to the next value. Strings must be written in quotes, so characters like comma, space, colon, graphical ones or control characters has to be written inside double quotes like string constants. The RESTORE resets the pointer of the current DATA position the program start so that next READ will read from the first DATA found from the beginning of the program.

In case READ uses the wrong variable type, variable will be untouched and pointer will be left to the current position. There is no easy way to get the position of the READ statement which is the real origin of the mismatch.

DATA lines may scattered over the whole program code.

SYNTAX

 DATA c1[, c2[, c3[, ...]]]
 DATA AS type c1[, c2[, c3[, ...]]]


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

ABBREVIATION: Da

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

DATA ↔ Da

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS