When we translate this into a program we are entitled not only to expect it to work but to know what it
will do. It will plot a rectangle made up of rows of pixels.
100 REMark Rows of pixels
110 PAPER 0 : CLS
120 FOR up = 30 TO 80
130 FOR across = 20 TO 60
140 INK RND(2 TO 7)
150 POINT across,up
160 END FOR across
170 END FOR up
Different structures may be nested. Suppose we replace the inner FOR loop of the above program by
a REPeat loop. We will terminate the REPeat loop when the zero colour code appears for a selection
in the range 0 to 7.
100 REMark REPeat in FOR
110 PAPER 0 : CLS
120 FOR up = 30 TO 80
130 LET across = 19
140 REPeat dots
150 LET colour = RND(7)
160 INK colour
170 LET across = across + 1
180 POINT across,up
190 IF colour = 0 THEN EXIT dots
200 END REPeat dots
210 END FOR up
Much of the wisdom about program control and structure can be expressed in two rules:
1. Construct your program using only the legitimate structures for loops and decision making.
2. Each structure should be properly related in sequence or wholly within another.
BINARY DECISIONS
The three types of binary decision can be illustrated easily in terms of what to do when when it rains.
Example 1:
100 REMark Short form IF
110 LET rain = RND(0 TO 1)
120 IF rain THEN PRINT "Open brolly"
Example 2:
100 REMark Long form IF. ..END IF
110 LET rain = RND(0 TO 1)
120 IF rain THEN
130 PRINT "Wear coat"
140 PRINT "Open brolly"
150 PRINT "Walk fast"
160 END IF
Example 3:
100 REMark Long form IF ...ELSE...END IF
110 LET rain = RND(0 TO 1)
120 IF rain THEN
130 PRINT "Take a bus"
140 ELSE
150 PRINT "Walk"
160 END IF