Sinclair QL Beginner's Manual page 11

Hide thumbs Also See for QL:
Table of Contents

Advertisement

252
You may notice that so far a variable name has always been used first on the left hand side of a LET
statement. Once the pigeon hole is set up and has a value, the corresponding variable name can be
used on the right hand side of a LET statement.
Now suppose you wish to encourage a small child to save money. You might give two bars of
chocolate for every pound saved. Suppose you try to compute this as follows:
LET bars = pounds * 2 
PRINT bars 
You cannot do a dry run as the program stands because you do not know how many pounds
have been saved.
We have made a deliberate error here in using pounds on the right of a LET statement without it
having been set up and give n some value. Your QL will search internally for the variable "pounds". It
will not find it, so it concludes that there is an error in the program and gives an error message. If we
had tried to print out the value of "pounds", the QL would have printed a * to indicate that "pounds"
was undefined. We say that the variable pounds has not been initialised (given an initial value). The
program works properly if you do this first.
LET pounds = 7 
LET bars = pounds * 2 
The program works properly and gives the output:
14
A STORED PROGRAM
Typing statements without line numbers may produce the desired result but there are two reasons
why this method, as used so far, is not satisfactory except as a first introduction.
1. The program can only execute as fast as you can type. This is not very impressive for a machine
that can do millions of operations per second.
2. The individual instructions are not stored after execution so you cannot run the program again or
correct an error without re-typing the whole thing.
Charles Babbage, a nineteenth century computer pioneer knew that a successful computer needed to
store instructions as well as data in internal pigeon holes. These instructions would then be executed
rapidly in sequence without further human intervention.
The program instructions will be stored but not executed if you use line numbers. Try this:
10 LET price = 15 
20 LET pens = 7 
30 LET cost = price * pens 
40 PRINT cost 
Nothing happens externally yet, but the whole program is stored internally. You make it work by
typing:
bars
pounds
7
7
14

Advertisement

Table of Contents
loading

Table of Contents