EasyManuals Logo

Sinclair QL Beginner's Guide

Sinclair QL
135 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #54 background imageLoading...
Page #54 background image
FOR loop. The program below produces scores of two dice in each row until a seven occurs, instead
of crosses.
100 REMark Dice rows
110 FOR row = 1 TO 4
120 PRINT 'Row number '! row
130 REPeat throws
140 LET die1 = RND(1 TO 6)
150 LET die2 = RND(1 TO 6)
160 LET score = die1 + die2
170 PRINT ! score !
180 IF score = 7 THEN EXIT throws
190 END REPeat throws
200 PRINT \'End of row '! row
210 END FOR row
sample output:
Row number 1
8 11 6 3 7
End of row number 1
Row number 2
4 6 2 9 4 5 12 7
End of row number 2
Row number 3
7
End of row number 3
Row number 4
6 2 4 9 9 7
End of row number 4
The third feature of loops in SuperBASIC allows more flexibility in providing the range of values in a
FOR loop. The following program illustrates this by printing all the divisible numbers from 1 to 20. (A
divisible number is divisible evenly by a number other than itself or 1.)
100 REMark Divisible numbers
110 FOR num = 4,6,8, TO 10,12,14 TO 16,18, 20
120 PRINT ! num !
130 END FOR num
More will be said about handling repetition in a later chapter but the features described above will
handle all but a few uncommon or advanced situations.
DECISION MAKING
You will have noticed the simple type of decision:
IF die = 6 THEN EXIT throws
This is available in most BASICs but SuperBASIC offers extensions of this structure and a completely
new one for handling situations with more than two alternative courses of action.
However, you may find the following long forms of IF..THEN useful. They should explain themselves.
(i)
100 REMark Long form IF. ..END IF
110 LET sunny = RND(0 TO 1)
120 IF sunny THEN
130 PRINT 'Wear sunglasses'
140 PRINT 'Go for walk'

Other manuals for Sinclair QL

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair QL and is the answer not in the manual?

Sinclair QL Specifications

General IconGeneral
ProcessorMotorola 68008
Clock Speed7.5 MHz
RAM128 KB (expandable to 640 KB)
ROM48 KB
Operating SystemSinclair QDOS
Release Year1984
StorageMicrodrive tape loop
Graphics256x256 pixels, 8 colors
PortsRS-232, ROM cartridge
SoundBeeper (internal speaker)

Related product manuals