70 MOVE xcentre%,ycentre%

80 PLOT 157,xcentre%+radius%,ycentre%

90 ENDPROC

RUN the program. The values of xcentre% and ycentre% are not affected by

PROCcircle. This is because any parameters passed to a procedure are

automatically local to that procedure. The xcentre%, ycentre% and radius% in

PROCcircle exist only within the procedure, and do not change the value of

variables with the same name elsewhere in the program.

All variables except parameters are global to a program. The whole program,

including procedures, 'knows' the value of the variables:

10 MODE 135

20 PROCname

30 PR0Cprint

40 END

50 DEFPR0Cname

60 INPUT"What is your name " ,name$

70 ENDPROC

80 DEFPR0Cprint

90 PRINT"This procedure is called PROCprint"

100 PRINT"It 'knows' your name is ";name$

110 ENDPROC

The string variable name$ is global. It is set up in PROCname, but PROCprint

also 'knows' name$ and uses it.

The distinction between local and global variables only becomes important if a

procedure contains global variables. For example, here is a procedure which

centres text on a given line:

100 DEFPR0Ccentre(text$)

110 Length%=LEN(text$)

120 x_position%=(40- length%) /2

130 PRINT TAB(x_position%) text$

140 ENDPROC

A useful procedure which might be called several times in a single program.

However, the procedure contains two global variables, length% and

x_position%. If variables of the same name are used in the program, their

values are lost after PROCcentre is called:

10 MODE 135

20 Length%=5

30 x_position%=15

40 PRINT" Length% is " ; Length%

C 34