EasyManuals Logo

Sinclair QL User Manual

Sinclair QL
422 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #44 background imageLoading...
Page #44 background image
CHAPTER
6
ARRAYS
AND
FOR
LOOPS
WHAT
IS
AN
ARRAY
You
know that numbers or character strings can become values of variables.
You
can
picture this
as
numbers or words gOing
Into
internal pigeon holes or houses. Suppose
for example that four employees
of
a company are
to
be sent
to
a small village, perhaps
because
all
has been discovered. The village
IS
one
of
the
few
places where the houses
only have names and there are four available
for
rent
All
the house names end with
a dollar symbol.
West/ea$
Lakes/de$ Rose/awn$ Oaktree$
The four employees are called:
They can be placed
in
the houses by one of two methods:
Program 1
100
LET
west
lea$
=
"VAL"
110
LET
Lakeside$
=
"HAL"
120
LET
roselawn$
=
I'MEL"
130
LET
oakt
ree$
=
"DEL"
140
PRINT I
westLea$
I
Lakeside$
I
roseLawn$
I
oaktree$
100
READ
westlea$,
Lakeside$,
roseLawn$,
oaktree$
110
PRINT I
westLea$
I
Lakeside$
I
roseLawn$
I
oaktree$
120
DATA
"VALli,
IIHALI!,
"MEL",
"DELli
Program 2
westlea$
I
VAL
lakeside$
I
HAL
roselawn$
I
MEL
oaktree$
. I
DEL
As
the amount of data gets larger the advantages
of
READ and
DATA
over LET become
greater.
But when
the
data gets really numerous the problem of finding names
for
houses
gets
as
difficult
as
finding vacant houses
in
a small village.
The solution
to
this and many other problems of handling data lies
in
a new type of
pigeon hole or variable
in
which many may share a
Single
name.
However,
they must
be distinct
so
each variable also has a number
like
numbered houses
in
the same street
Suppose that you need four vacant houses
in
High Street numbered 1
to
4.
In
SuperBASIC
we
say
there
IS
an array of four houses. The name of the array
is
high_st$
and the four houses are
to
be numbered 1
to
4.
But you cannot
Just
use these array variables
as
you
can ordinary (simple) variables.
You
have
to
declare the dimensions (or
size)
of
the
array
first The computer allocates
space internally and
It
needs
to
know how many string variables there are
In
the array
and also the maximum length of each string variable.
You
use a DIM statement thus:
DIM high_st$(4,3)
11-
maximum length of string
L-
number of string variables
After the DIM statement has been executed the variables are available
for
use.
It
is
as
though the houses have been
bUilt
but are
still
empty. The four 'houses' share a common
nam~
hlgh-st$,
but
each
has
its
own number and each can hold up
to
three characters:
~
ffi
~~~
ffi ffi
ffi
28
12/84

Other manuals for Sinclair QL

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair QL and is the answer not in the manual?

Sinclair QL Specifications

General IconGeneral
ProcessorMotorola 68008
Clock Speed7.5 MHz
RAM128 KB (expandable to 640 KB)
ROM48 KB
Operating SystemSinclair QDOS
Release Year1984
StorageMicrodrive tape loop
Graphics256x256 pixels, 8 colors
PortsRS-232, ROM cartridge
SoundBeeper (internal speaker)

Related product manuals