Sinclair QL Beginner's Manual page 56

Hide thumbs Also See for QL:
Table of Contents

Advertisement

The power and simplifying effects of procedures are more obvious as programs get larger. What
procedures do as programs get larger is not so much make programming easier as prevent it from
getting harder with increasing program size. The above example just illustrates the way they work in a
simple context.
Examples
The following examples indicate the range of vocabulary and syntax of SuperBASIC which has been
covered in this and earlier chapters, and will form a foundation on which the second part of this
manual will build.
The letters of a palindrome are given as single items in DATA statements. The terminating item is an
asterisk and you assume no knowledge of the number of letters in the palindrome. READ the letters
into an array and print them backwards. Some palindromes such as "MADAM I'M ADAM" only work if
spaces and punctuation are ignored. The one used here works properly.
100 REMark Palindromes
110 DIM text$(30)
120 LET text$ = FILL$ (' ',30)
130 LET count = 30
140 REPeat get_letters
150
READ character$
160
IF character$ = '*' THEN EXIT get_letters
170
LET count = count-1
180
LET text$(count) = character$
190 END REPeat get_letters
200 PRINT text$
210 DATA 'A','B','L','E','W','A','S','I','E','R'
220 DATA 'E','I','S','A','W','E','L','B','A','*'
The following program accepts as input numbers in the range 1 to 3999 and converts them into the
equivalent In Roman numerals It does not generate the most elegant form. It produces IIII rather than
IV.
100 REMark Roman numbers
110 INPUT number
120 RESTORE 210
130 FOR type = 1 TO 7
140
READ letter$, value
150
REPeat output
160
IF number < value : EXIT output
170
PRINT letter$;
180
LET number = number - value
190
END REPeat output
200 END FOR type
210 DATA 'M',1000,'D',500,'C',100,'L',50,'X',10,'V',5,'I',1
You should study the above examples carefully using dry runs if necessary until you are sure that you
understand them.
CONCLUSION
In SuperBASIC full structuring features are provided so that program elements either follow in
sequence or fit into one another neatly. All structures must be identified to the system and named.
There are many unifying and simplifying features and many extra facilities.
Most of these are explained and illustrated in the remaining chapters of this manual, which should be
easier to read than the Keyword and Concept Reference sections. However, it is easier to read
because it does not give every technical detail and exhaust every topic which it treats. There may,
therefore, be a few occasions when you need to consult the reference sections. On the other hand
some major advances are discussed in the following chapters. Few readers will need to use all of
them and you may find it helpful to omit certain parts, at least on first reading.

Advertisement

Table of Contents
loading

Table of Contents