Sinclair QL User Manual page 52

Hide thumbs Also See for QL:
Table of Contents

Advertisement

Smple Proce6Jres
100 PAPER 7: CLS
110 INK 4
120 square 20,SO,SO
The numbers
20,50,50
are called parameters and they are passed to the variables named
In the procedure definition thus:
sq uare
20,50,50
I J.,/.
DEFine PROCedure square(side,ac,up)
The numbers
20,50,50
are called actual parameters, They are numbers in this case but
they could be variables or expressions, The variables slde,ae,up are called formal
parameters. They must be variables because the 'receIVE' values.
A more interesting main program uses the same procedure to create a random pattern
of coloured pairs of squares. Each pair of squares is obtained by offsetting the second
one across and up by one-fifth of the side length thus:
36
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 pa i r = 1 TO 20
130
INK RND(S)
140
LET side = RND(10 TO 20)
1S0
LET ac = RND (SOl : up = RND (70l
160
square side,ac,up
170
LET ac=ac+side/S : up = up+side/S
180
square side,ac,up
190 END FOR pai r
The advantage 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.
12/84

Advertisement

Table of Contents
loading

Table of Contents