Sinclair QL Beginner's Manual page 35

Hide thumbs Also See for QL:
Table of Contents

Advertisement

DIM high_st$(4, 3)
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 name, high_st$, but
each has its own number and each can hold up to three characters.
There are five programs below which all do the same thing: they cause the four 'houses' to be
'occupied' and they PRINT to show that the 'occupation' has really worked. The final method uses
only four lines but the other four lead up to it in a way which moves all the time from known ideas to
new ones or new uses of old ones. The movement is also towards greater economy.
If you understand the first two or three methods perfectly well you may prefer to move straight onto
methods 4 and 5. But if you are in any doubt, methods 1, 2 and 3 will help to clarify things.
Program 1
100 DIM high_st$(4,3)
110 LET high_st$(l) = "VAL"
120 LET high_st$(2) = "HAL"
130 LET high_st$(3) = "MEL"
140 LET high st$(4) = "DEL"
150 PRINT ! high_st$(1) ! high st$(2) !
160 PRINT ! high_st$(3) ! high-st$(4) !
Program 2
100 DIM high st$(4,3)
110 READ high_st$(1),high_st$(2),high_st$(3),high_st$(4)
120 PRINT ! high_st$(1) ! high_st$(2) !
130 PRINT ! high_st$(3) ! high_st(4) !
140 DATA "VAL","HAL","MEL","DEL"
This shows how to economise on variable names but the constant repeating of high_st$ is both
tedious and the cause of the cluttered appearance of the programs. We can, again, use a known
technique - the REPeat loop to improve things further. We set up a counter, number, which increases
by one as the REPeat loop proceeds.
Program 3
100 RESTORE 190
110 DIM high_st$(4,3)
120 LET number = 0
130 REPeat houses
140
LET number = number + 1
150
READ high_st$(number)
160
IF num = 4 THEN EXIT houses
170 END REPeat houses
180 PRINT high_st$(1) ! high_st$(2) ! high_st$(3) ! high_st$(4)
190 DATA "VAL","HAL","MEL","DEL"
:
|
|
|
------ maximum length of string
|
--------- number of string variables

Advertisement

Table of Contents
loading

Table of Contents