Sinclair QL Beginner's Manual page 93

Hide thumbs Also See for QL:
Table of Contents

Advertisement

ARRAY SLICING
You may find this section hard to read though it is essentially the same concept as string slicing. You
will probably need string-slicing if you get beyond the learning stage of programming. The need for
array-slicing is much rarer and you may wish to omit this section particularly on a first reading.
We now use the golfers' flats to illustrate the concept of array slicing. The flats will be numbered 0 to 9
to keep to single digits and names will be single characters for space reasons.
Given the above values the following are array slices:
flat$(1,3)
flat$(1,1 TO 6)
Array Element
flat$(1,1)
flat$(1,2)
flat$(1,3)
flat$(1,4)
flat$(1,5)
flat$(1,6)
flat$(1)
In these examples a range of values of a subscript can be given instead of a single value. If a
subscript is missing completely the complete range is assumed. In the third example the second
subscript is missing and it is assumed by the system to be 0 TO 9.
The techniques of array slicing and string slicing are similar though the latter is more widely
applicable.
PROBLEMS ON CHAPTER 13
1. SORTING
Place ten numbers in an array by reading from a DATA statement. Search the array to find the lowest
number. Make this lowest number the value of the first element of a new array. Replace it in the first
array with a very large number. Repeat this process making the second lowest number the second
value in the new array and so on until you have a sorted array of numbers which should then be
printed.
2. SNAKES AND LADDERS
Means a single array element with value N
Means six elements with values L M N 0 P Q
Value
L
M
N
O
P
Q
means flat$(1,0 TO 9)
Ten elements with values K L M N O P Q R S T

Advertisement

Table of Contents
loading

Table of Contents