Variables - Sinclair ZX81 User Manual

Hide thumbs Also See for ZX81:
Table of Contents

Advertisement

Chapter 6 - Variables
'My pocket calculator,' you will be saying, 'can store a number away & remember it later. Can your ZX81 do
that?'
Yes. In fact it can store away literally hundreds, using the LET statement. Suppose that eggs cost 58p a
dozen, & you want to remember this. Type
LET EGGS=58
Now first, the computer has reserved a place inside itself where you can store a number, & second, it
has given this place the name 'EGGS' so you can refer to it later. This combination of storage space &
name is called a variable. Third, it has stored the number 58 in the space: we say that it has assigned the
value 58 to the variable [whose name is] EGGS. EGGS is a numeric variable, because its value is a
number.
Do you want to know how much eggs cost? Type
PRINT EGGS
If you want to know the cost of half a dozen eggs, then type
PRINT EGGS/2
In fact, should you want to know the square of the consine of the price of one egg, you can type
PRINT COS (EGGS/12)**2
'How very easy,' you must think, & you will be wondering what to do next, when in rushes your
housekeeper saying 'Glory be, eggs have just gone up to 61p a dozen.'
Well. There is no time to lose. Type
LET EGGS=61
This does not reserve any extra storage space, but replaces the old value of 58 with 61. Now you can
type
PRINT EGGS
confident in the expectation of getting the most up-to-date price available.
Now type
PRINT MILK
You will get a report 2/0, & looking up 2 in appendix B, you will see that it means 'variable not found' -
the computer hasn't tha faintest idea how much milk costs, because you haven't told it. Type
LET MILK=18.5
& all will be all right.
(Type
PRINT MILK
again.)
A variable need not be named after groceries - you can use any letters or digits as long as the first one
is a letter. You can put spaces in as well to make it easier to read, but they won't count as part of the
name.
For instance, these are allowed to be the names of variables:
TWO POUNDS OF APPLES BUT NOT GOLDEN DELICIOUS
RADIO 3
(& NEWLINE , of course)

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents