Sinclair QL Beginner's Manual page 34

Hide thumbs Also See for QL:
Table of Contents

Advertisement

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 oil 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.
Westlea$ Lakeside$ Roselawn$ Oaktree$
The four employees are called:
VAL
They can be placed in the houses by one of two methods.
Program 1:
100 LET westlea$ = "VAL"
110 LET lakeside$ = "HAL"
120 LET roselawn$ = "MEL"
130 LET oaktree$ = "DEL"
140 PRINT ! westlea$ ! lakeside$ ! roselawn$ ! oaktree$
Program 2:
100 READ westlea$, lakeside$, roselawn$, oaktree$
110 PRINT ! westlea$ ! lakeside$ ! roselawn$ ! oaktree$
120 DATA "VAL", "HAL", "MEL", "DEL"
Westlea$
VAL
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:
HAL
Lakeside$
HAL
MEL
Roselawn$
MEL
DEL
Oaktree$
DEL

Advertisement

Table of Contents
loading

Table of Contents