|Liberty BASIC Help Online
The DATA statement provides a convenient way to insert data into programs. The DATA can be read once or many times using the READ statement. A DATA statement doesn't actually perform an action when it is encountered in the program's code.
'read the numbers and their descriptions
while desc$ <> "end"
read desc$, value
print desc$; " is the name for "; value
'here is our data
data "one", 1, "two", 2, "three", 3, "end", 0
One or more DATA statements form the whole set of data elements. For example, the data represented in the example above can also be listed in more than one DATA statement:
'here is our data in two lines instead of one
data "one", 1, "two", 2
data "three", 3, "end", 0
DATA is local to the subroutine or function it is defined in.
An attempt to read more DATA items than are contained in the DATA lists causes the program to halt with an error. Notice that in the examples above, an "end" tag is placed in the DATA and when it is reached, the program stops READing DATA. This is an excellent way to prevent errors from occuring. If an end tag or flag of some sort is not used, be sure that other checks are in place to prevent the READ statement from trying to access more DATA items than are contained in the DATA statements.
Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/