91 80 PRINT "IN PROCEDURE J= ";J 90 ENDPROC >RUN IN PROCEDURE J= 1 OUT OF PROCEDURE J= 25 IN PROCEDURE J= 2 OUT OF PROCEDURE J= 25 IN PROCEDURE J= 3 OUT OF PROCEDURE J= 25 IN PROCEDURE J= 4 OUT OF PROCEDURE J= 25 IN PROCEDURE J= 5 OUT OF PROCEDURE J= 25 In the program above the variable J is used in two ways. The main program starts at line 10 and ends at line 60. The procedure is defined between lines 70 and 90. Line 10 declares that J has the value 25 and the value of J is not changed in the main program. However J is used as the formal parameter in the procedure. All formal parameters are local to the procedure which means that their value is not known to the rest of the program.
Inside the procedure, J takes on the value of the actual parameter X, but outside the procedure it has a different value. The distinction is made between global variables and local variables. Global variables are known to the whole program, including procedures, whereas local variables are only known to those procedures in which they are defined and to procedures within that procedure. In the program above, X is a global varible and it looks as if J is global too, since it is defined in line 10 of the main program. In fact that J is global but the use of the parameter J in the procedure creates another variable J which is local to the procedure.
If a different parameter had been used in the procedure definition then J would have remained global. Thus in the program below the formal parameter has been changed to K in line 70, which leaves J as a global variable. 10 J=25 20 FOR X=1 TO 5 30 PROCNUM(X) 40 PRINT "OUT OF PROCEDURE J= ";J 50 NEXT X 60 END 70 DEF PROCNUM(K) 80 PRINT "IN PROCEDURE J= ";J 90 ENDPROC >RUN IN PROCEDURE J= 25