07.05.2015 Views

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12. Using and Storing Data 79<br />

times it’s more convenient to put them right after a READ statement. You may use a separate<br />

DATA statement for each item, or use commas to put several items on one statement.<br />

<strong>True</strong> <strong>BASIC</strong> lumps all the DATA statements in a program together, in order, into one long<br />

list of data items. Each time it executes a READ statement, <strong>True</strong> <strong>BASIC</strong> reads the next<br />

item in the DATA list, regardless of where it appeared in the program.<br />

———————————————————————————————————————<br />

x READ and DATA statements can use either numbers or strings.<br />

———————————————————————————————————————<br />

You may freely mix strings and numbers in your DATA statements. Just be sure that the<br />

variable name type (numeric or string) is reading an appropriate type of data item. You<br />

can’t read a string data item into a numeric variable, but you can read a number into a string<br />

variable. The TRIVIA program reads some numbers for the string variable answer$. This<br />

is perfectly legal in <strong>True</strong> <strong>BASIC</strong>, as long as you don’t try to use that variable to do arithmetic<br />

calculations.<br />

———————————————————————————————————————<br />

x You must put double quote marks around string data items that contain<br />

commas, or around items that begin or end with spaces.<br />

———————————————————————————————————————<br />

If you don’t use quote marks, <strong>True</strong> <strong>BASIC</strong> will assume that any commas are separating data<br />

items, and it will ignore any extra spaces before or after the data.<br />

Checking for More Data<br />

The TRIVIA program stores the number of questions in the first item in the DATA statements.<br />

The number of questions then controls the FOR-NEXT loop so that it reads the correct<br />

number of items. If the program tried to read more items than are contained in the<br />

DATA statements, <strong>True</strong> <strong>BASIC</strong> would give you an error message.<br />

It is not always convenient to count the number of DATA statement items, however. <strong>True</strong><br />

<strong>BASIC</strong> provides a way that you can use a DO loop to check whether there are any more data<br />

items available. The SMOKY demo program you edited in the last chapter illustrates this<br />

method. You haven’t learned the PLAY statement yet for performing music, but you should<br />

be able to follow the logic of the program.<br />

! Plays the beginning of<br />

! “On Top of Old Smoky”.<br />

DO while more data

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!