Sinclair QL Beginner's Manual page 90

Hide thumbs Also See for QL:
Table of Contents

Advertisement

This will output the values only:
0
50
37
86
41
32
The zero at the top of the list appears because subscripts range from zero to the declared number.
We will show later how useful the zero elements in arrays can be. Note also that when a numeric
array is DIMensioned its elements are all given the value zero.
STRING ARRAYS
String arrays are similar to numeric arrays but an extra dimension in the DIM statement specifies the
length of each string variable in the array. Suppose that ten of the top players at Royal Birkdale for the
1982 British Golf Championship were denoted by their first names and placed in DATA statements.
DATA "Tom","Graham","Sevvy","Jack","Lee"
DATA "Nick","Bernard","Ben","Gregg","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 'flats':
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$(1) : REMark Tom into temporary
LET flat$(1) = flat$(3) : REMark Sevvy into flat$(1)
LET flat$(3) = temp$ : REMark Tom into flat$(3)

Advertisement

Table of Contents
loading

Table of Contents