3.8.2 Global Variables
Description
On the other hand, global variables defined as global can always be accessed from all job programs. If a global variable is once defined, it will not be cleared even when the program cycle is reset by an end statement or an R0 [Enter] operation of the main program.
Example
If a global x is executed first, a variable x will be created, and the value will be initialized to the default value of 0. Then, it will increase to 1 in the next row. If the global x is executed again in the next program cycle, it will not be defined again, and the value of 1 will be retained because the x has been defined. On the other hand, global y=10 will carry out defining and assignment so that the value of variable y will be reset to 10 when it is executed in the next program cycle.
0001.job
global x
x=x+1
call 107
print x, y # 4, 10
end
0107.job
global y=10
print x, y # 3, 10
x=x+1
end
Therefore, if a global variable is to be utilized as a counter for the number of program cycles, no value should be assigned along with a definition.
Wrong
Teaching
global count=0
count=count+1
…
end
Correct
Teaching
global count
count=count+1
…
end
Last updated
Was this helpful?