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 #91 background imageLoading...
Page #91 background image
•
•
String arrays
are
similar
to
numeric arrays but
an
extra dimension
in
the DIM statement
STRING
ARRAYS
speCities
the length
of
each string variable
In
the array Suppose
that
ten
of
the
top
players
at
Royal
Birkdale
for
the
1982
British
Gol$'Championshlp
were
denoted
by
their
first
names
and placed
in
DATA
statements.
DATA
"Tom", "Graham",
IlS
evvy
",
"Jack
ll
,
"Lee"
DATA
"Nick",
"Bernard",
"Ben
ll
,
"Gregg
l
',
"Hal"
You
would need
ten
different variable names, but
If
there were a hundred or a thousand
players the job would become
impossibly tedious. An array
IS
a
set
of
variables designed
to
cope with problems
of
this kind. Each variable name consists
of
two
parts:
a name according
to
the usual
rules
a numeric part called a
subSCript
Write
the variable names
as:
flat$(1),
flat$(2),
fLat$(3)
...
etc
Before you can use the array variables
you
must
tell
the
system
about the array and
its
dimensions:
DIM
flat$(10,8)
This
caUSes
eleven
(0
to
10)
variables
to
be reserved
for
use
in
the program.
Each
string
variable
In
the array may
have
up
to
eight characters. DIM statements should usually
be placed
all
together near the beginning
of
the program. Once the array has been
declared
In
a DIM statement
all
the elements
of
the array can be used. One important
advantage
is
that you can give the numeric part (the subscript)
as
a
numeriC
variable.
You
can write:
FOR
number =1
TO
10:
READ
fLat$(number)
ThiS
would place the golfers
in
their ilats:
Arrays
Ilal$(1)
G
Ilal$(2)
IGraham I
Ilal$(3) lIal$(10)
EJ
0
Sevvy
Hal
--~------------
•
You
can refer
to
the variables
in
the usual
way
but remember
to
use the right subscript.
Suppose that
Tom
and Sevvy
Wished
to
exchange
flats.
In
computing terms one
of
them,
Tom
say,
would
have
to
move into a temporary flat
to
allow Sevvy time
to
move.
You
can
write:
LET
temp$ =
flat$(1J:
REMark
Tom
into
temporary
LET
flat$(1)
=
flat$(3):
REMark
Sevvy
into
flat$(1J
LET
flat$(3)
=
temp$:
REMark
Tom
into
flat$(3)
The following program places the
ten
golfers
in
an
array named
flat$
and prints the
names
of
the occupants
with
their ilat numbers' (array
subSCripts)
to
prove that
they
are
in
residence
The
occupants
of
flats
1 and 3 then change places.
The
list
01
occupants
is
then printed again
to
show that the exchange has occurred.
100
REMark
Golfers'
FLats
110
DIM
flat$(10,8)
120
FOR
number =1
TO
10:
READ
flat$(number)
130
printlist
140
exchange
150
printlist
160
REMark
End
of
main
program
170
DEFine PROCedure
printList
180
FOR
num
= 1
TO
10
: PRINT num,
flat$(num)
190
END
DEFi ne
200 DEFine PROCedure
exchange
210
LET
temp$ =
fLat$(1J
220
LET
flat$(1) flat$(3)
230
LET
f
Lat$(3)
=temp$
240
END
DEFine
250
DATA
"Tom", "Graham",
"Sevvy",
IlJack",
"Lee"
260
DATA
"Nick",
"Bernard",
"Ben
ll
,
"Greg",
"HaL"
12/R4
75

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