3.8.1 Local Variables
Description
Examples have been described only using the examples of local variables defined with the var statement. Local variables are created by a var statement in one job program and are automatically destroyed when the program ends after the encounter with the end statement. Moreover, their values cannot be read or written by other programs.
Example
“main_v” is a local variable accessible only within 0001.job, and “sub_v” is a local variable accessible only within 0107.job. Attempting to access it from another program will cause an error.
The local variable “x” is defined in both 0001.job and 0107.job. The local variable “x” respectively defined in both programs has the same name but are different. So the value 5 for the variable “x” is set in subprogram 0107, 3 will be printed instead of 5 after the return to main program 0001.
0001.job
var main_v=10
var x=3
call 107
print main_v # ok
print sub_v # error
print x # 3 is printed
end
0107.job
var sub_v=20
var x
print sub_v # ok
print main_v # error
x=5
end
Last updated
Was this helpful?