Sinclair QL Beginner's Manual page 103

Hide thumbs Also See for QL:
Table of Contents

Advertisement

270
END SELect
280
IF across < 1 OR across > 99 OR up < 1 OR up > 99 : EXIT
snake
290
POINT across,up
300
END FOR unit
310 END REPeat snake
320 PRINT "Snake off edge"
The syntax of the SELect ON structure also allows for the possibility of selecting on a list of values
such as
5,6,8,10 TO 13
It is also possible to allow for an action to be executed if none of the stated values is found. The full
structure is of the form given below.
LONG FORM
SELect ON num
ON num = list of values
statements
ON num = list of values
Statements
-
-
-
-
ON num = REMAINDER
statements
END SELect
where num is any numeric variable and the REMAINDER clause is optional.
SHORT FORM
There is a short form of the SELect structure. For example:
100 INPUT num
110 SELect ON num = 0 TO 9 : PRINT "digit"
will perform as you would expect.
PROBLEMS ON CHAPTER 14
1. Store 10 numbers in an array and perform a 'bubble-sort'. This is done by comparing
pair and exchanging, if necessary the second pair (second and third numbers),
pair (ninth and tenth numbers). The first run of nine comparisons and possible exchanges
guarantees that the highest number will reach its correct position. Another eight runs will
guarantee eight more correct positions leaving only the lowest number which must be in the only
(correct) position left. The simplest form of 'bubble sort' of ten numbers requires nine runs of nine
comparisons.
2. Consider ways of speeding up bubblesort, but do not expect that it will ever be very efficient.
3. An auctioneer wishes to sell an old clock and he has instructions to invite a first bid of £50. If no-
one bids he can come down to £40, £30, £20, but no lower, in an effort to start the bidding. If no-
one bids, the clock is withdrawn from the sale. When the bidding starts, he takes only £5
increases until the final bid is made. If the final bid is £35 (the 'reserve price') or more, the clock is
sold. Otherwise it is withdrawn.
the first
up to the ninth

Advertisement

Table of Contents
loading

Table of Contents