Sinclair QL Beginner's Manual page 107

Hide thumbs Also See for QL:
Table of Contents

Advertisement

100 REMark LOCAL parameter
110 LET num = 70
120 item 3
130 item 4
140 PRINT ! num !
150 DEFine PROCedure item(num)
160
IF num <= 3 THEN LET price = 300 + 10*num
170
IF num >= 4 THEN LET price = 12*num
180
PRINT ! price !
190 END DEFine
Output
330 48 70
VARIABLE PARAMETERS
So far we have only used procedure parameters for passing values to the procedure. But suppose the
main program wants the cost of an item to be passed back so that it can compute the total bill. We
can do this easily by providing another parameter in the procedure call. This must be a variable
because it has to receive a value from the procedure. We therefore call it a variable parameter and it
must be matched by a corresponding variable parameter in the procedure definition.
EXAMPLE
Use actual variable parameters, cost_1 and cost_2 to receive the values of the variable price from the
procedure. Make the main program compute and print the total bill.
Program
100 REMark Variable parameter
110 LET num = 70
120 item 3,cost_1
130 item 4,cost_2
140 LET bill = num + cost_1 + cost_2
150 PRINT bill
160 DEFine PROCedure item(num,price)
170
IF num <= 3 THEN LET price = 300 + 10*num
180
IF num >= 4 THEN LET price = 12*num
190 END DEFine
Output
448
The parameters num and price are both automatically local so there can be no problems. The
diagrams show how information passes from main program to procedure and back.
That is enough about procedures and parameters for the present.
FUNCTIONS
You already know how a system function works. For example the function:

Advertisement

Table of Contents
loading

Table of Contents