Sinclair QL Beginner's Manual page 53

Hide thumbs Also See for QL:
Table of Contents

Advertisement

If you know other languages you may see that it will do the jobs of both REPEAT and WHILE
structures and also cope with other more awkward, situations.
The SuperBASIC REPeat loop is named so that a correct clear exit is made. The FOR loop, like all
SuperBASIC structures, ends with END, and its name is given for reasons which will become clear
later.
You will also see later how these loop structures can be used in simple or complex situations to match
exactly what you need to do. We will mention only three more features of loops at this stage. They will
be familiar if you are an experienced user of BASIC.
The increment of the control variable of a FOR loop is normally 1 but you can make it other values by
using the STEP keyword. As the examples show.
Example (i).
100 FOR even = 2 TO 10 STEP 2
110 PRINT ! even !
120 END FOR even
2 4 6 8 10
output is
Example (ii).
100 FOR backwards = 9 TO 1 STEP -1
110 PRINT ! backwards !
120 END FOR backwards
output is 9 8 7 6 5 4 3 2 1
The second feature is that loops can be nested. You may be familiar with nested FOR loops. For
example the following program outputs four rows of ten crosses.
100 REMark Crosses
110 FOR row = 1 TO 4
120 PRINT 'Row number' ! row
130
FOR cross = 1 TO 10
140
PRINT ! 'X' !
150 END FOR cross
160 PRINT
170 PRINT \ 'End of row number' ! row
180 END FOR row
output is:
Row number 1
X X X X X X X X X X
End of row number 1
Row number 2
X X X X X X X X X X
End of row number 2
Row number 3
X X X X X X X X X X
End of row number 3
Row number 4
X X X X X X X X X X
End of row number 3
A big advantage of SuperBASIC is that it has structures for all purposes, not just FOR loops, and they
can all be nested one inside the other reflecting the needs of a task. We can put a REPeat loop in a

Advertisement

Table of Contents
loading

Table of Contents