Sinclair QL Beginner's Manual page 14

Hide thumbs Also See for QL:
Table of Contents

Advertisement

4 
Do not forget the ENTER key. The output will be:
60
The INPUT statement needs a variable name so that the system knows where to put the data which
comes in from your typing at the keyboard. The effect of line 30 with your typing is the same as a LET
statement's effect. It is more convenient for some purposes when interaction between computer and
user is desirable. However, the LET statement and the INPUT statement are useful only for modest
amounts of data. We need something else to handle larger amounts of data without pauses in the
execution of the program.
SuperBASIC, like most BASICs, provides another method of input known as READing from DATA
statements. We can retype the above program in a new form to give the same effects without any
pauses. Try this:
NEW 
10 READ price, pens 
20 LET cost = price * pens 
30 PRINT cost 
40 DATA 15, 4 
RUN 
The output should be:
60
as before.
Each time the program is run, SuperBASIC needs to be told where to start reading DATA from. This
can either be done by typing RESTORE followed by the DATA line number or by typing CLEAR. Both
these commands can also be inserted at the start of the programs.
When line 10 is executed the system searches the program for a DATA statement. It then uses the
values in the DATA statement for the variables in the READ statement in exactly the same order. We
usually place DATA statements at the end of a program. They are used by the program but they are
not executed in the sense that every other line is executed in turn. DATA statements can go
anywhere in a program but they are best at the end, out of the way. Think of them as necessary to,
but not really part of, the active program. The rules about READ and DATA are as follows:
1. All DATA statements are considered to be a single long sequence of items. So far these items
have been numbers but they could be words or letters.
2. Every time a READ statement is executed the necessary items are copied from the DATA
statement into the variables named in the READ statement.
3. The system keeps track of which items have been READ by means of an internal record. If a
program attempts to READ more items than exist in all the DATA statements an error will be
signalled.
IDENTIFIERS (NAMES)
You have used names for 'pigeon holes' such as "dogs", "bars". You may choose words like these
according to certain rules:
A name cannot include spaces.
A name must start with a letter.
A name must be made up from letters, digits, $, %, _ (underscore)

Advertisement

Table of Contents
loading

Table of Contents