Sinclair QL Beginner's Manual page 44

Hide thumbs Also See for QL:
Table of Contents

Advertisement

Assuming that the procedure square is still present at line 200 then the following program
will have the classical effect.
100 REMark Squares Pattern
110 PAPER 7 : CLS
120 FOR pair = 1 TO 20
130
INK RND(5)
140
LET side = RND(10 TO 20)
150
LET ac = RND(50) : up = RND(70)
160
square side,ac,up
170
LET ac=ac+side/5 : up = up+side/5
180
square side,ac,up
190 END FOR pair
The advantages of procedures are:
1.
You can use the same code more than once in the same program or in others.
2.
You can break down a task into sub-tasks and write procedures for each sub-task. This helps
the analysis and design.
3.
Procedures can be tested separately. This helps the testing and debugging.
4.
Meaningful procedure names and clearly defined beginnings and ends help to make a
program readable.
When you get used to properly named procedures with good parameter facilities, you should find that
your problem-solving and programming powers are greatly enhanced.
SELF TEST ON CHAPTER 7
You can score a maximum of 14 points from the following test. Check your score with the "Answers
To Self Tests" section at the back of this Beginner's Guide.
1. How do we normally tackle the problem of great size and complexity in human affairs?
2. How can this principle be applied in programming?
3. What are the two most obvious features of a simple procedure definition? (two points)
4. What are the two main effects of using a procedure name to 'call' the procedure? (two points)
5. What is the advantage of using procedure names in a main program before the procedure
definitions are written?
6. What is the advantage of writing a procedure definition before using its name in a main program?
7. How can the use of procedures help a 'thirty-line-programmer' to write much bigger programs?

Advertisement

Table of Contents
loading

Table of Contents