Sinclair QL Beginner's Manual page 52

Hide thumbs Also See for QL:
Table of Contents

Advertisement

;
just separates - no formatting effect
\
forces new line
!
normally provides a space but not at the start of line. If an item will
not fit at the end of a line it performs a new line operation.
TO
Allows tabulation to a designated column position.
You will be familiar with two types of repetitive loop exemplified as follows:
(a) Simulate 6 throws of an ordinary six-sided die
100 FOR throw = 1 TO 6
110 PRINT RND(1 TO 6)
120 NEXT throw
(b) Simulate throws of a die until a six appears.
100 die = RND(1 TO 6)
110 PRINT die
120 IF die <> 6 THEN GOTO 10
Both of these programs will work in SuperBASIC but we recommend the following instead. They do
exactly the same jobs. Although program (b) is a little more complex there are good reasons for
preferring it.
Program (a)
100 FOR throw = 1 TO 6
110 PRINT RND(1 TO 6)
120 END FOR throw
Program (b)
100 REPeat throws
110 die = RND(1 TO 6)
120 PRINT die
130 IF die = 6 THEN EXIT throws
140 END REPeat throws
It is logical to provide a structure for a loop which terminates on a condition (REPeat loops) as well as
those which are controlled by a count.
The fundamental REPeat structure is:
REPeat identifier
statements
END REPeat identifier
The EXIT statement can be placed anywhere in the structure but it must be followed by an identifier to
tell SuperBASIC which loop to exit; for example:
EXIT throws
would transfer control to the statement after
END REPeat throws.
This may seem like a using a sledgehammer to crack the nut of the simple problem illustrated.
However the REPeat structure is very powerful. It will take you a long way.

Advertisement

Table of Contents
loading

Table of Contents