in
mathematics.
Instructing
llle
Computer
A statement such
as:
LET
dogs
=9
..
"
is
an
Instruction
for
a highly dynamic Internal process but the printed text
is
static and
it
uses the = sign borrowed from mathematics.
It
is
better
to
think or
say
(but not type):
LET
dogs
become 9
and
to
think of the process having a right
to
left direction (do not type
this):
dogs
<?
9
The use of =
in
a LET statement
is
not the same
as
the use of
For
example,
if
another dog turns
up
you
may wish
to
write:
LET
dogs::
dogs
+
1.11
Mathematically, this
is
not very sensible but
in
terms
of
computer operations
it
is
simple.
If
the value of dogs before the operation was 9 then the value after the operation would
be
10.
Test
this
by
typing:
LET
dog
s = 9
..
"
PRINT
dogs.1I
LET
dogs
=
dogs
+ 1
..
"
PRINT
dogs
..
"
The output should be:
9
10
proving that the final value
in
the pigeon hole
is
as
shown:
d09S[:]
•
•
8
A good way
to
understand what
is
happening
to
the pigeon holes, or variables,
is
to
do
what
is
called a 'dry
run:
You
simply examine each instruction
in
turn and write down
the values which result from each instruction
to
show how the pigeon holes are set up
and given values, and how they retain their values
as
the program
is
executed.
LET
dogs
= 9
..
"
LET
days
=
28
..
" •
LET
tins::
dogs
*
days.11
PRINT
tins_II
The output should be:
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.1I
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 given some
value.
Your
OL
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
OL
•
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:
12/84