Sinclair QL Beginner's Manual page 20

Hide thumbs Also See for QL:
Table of Contents

Advertisement

REPeat star
END REPeat star
and what lies between them is called the content of the structure. The use of upper case letters
indicates that REP is a valid abbreviation of REPeat.
This program should produce coloured lines indefinitely to make a star as shown in the figure below.
You can stop it by pressing the break keys:
Hold down CTRL and then press
SuperBASIC provides a consistent and versatile method of stopping repetitive processes.
Imagine running round and round inside the program activating statements. How can
you escape? The answer is to use an EXIT statement. But there must be some reason
for escaping. You might extend the choice of line colours by typing as an amendment
to the program (do not type NEW):
40 INK RND (0 TO 6) 
so that if RND produces 6 the ink is the same colour as the paper and you will not see
it. This could be the reason for terminating the repetition. We can re-arrange the
program as follows:
NEW 
10 PAPER 6 : CLS 
20 BORDER 1 ,2 
30 REPeat star 
LET colour = RND(6) 
40
IF colour = 6 THEN EXIT star 
50
INK colour 
60
LINE 50,60 TO RND(100),RND(100) 
70
80 END REPeat star 
The important thing to note here is that the program continues until "colour" becomes 6. Control then
escapes from the loop to the point just after line 80. Since there are no program lines after 80 the
program stops.
Another important concept has been introduced. It is the idea of a decision.
IF colour = 6 THEN EXIT star
The STAR program
SPACE
.

Advertisement

Table of Contents
loading

Table of Contents