> For the complete documentation index, see [llms.txt](https://hyundai-robotics.gitbook.io/hi6-robot-language/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hyundai-robotics.gitbook.io/hi6-robot-language/rl-english/flowcontrol-subprogram/local-global-var/3.8.2-global-variables.md).

# 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 | <p>global x |

</p><p>x=x+1</p><p>call 107</p><p>print x, y  # 4, 10</p><p>end</p> |
| 0107.job | <p>global y=10</p><p>print x, y  # 3, 10</p><p>x=x+1</p><p>end</p>              |

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.

|          |   |
| -------- | - |
| <p>Wrong |   |

</p><p>Teaching</p>   | <p>global count=0</p><p>count=count+1</p><p>…</p><p>end</p> |
| <p>Correct</p><p>Teaching</p> | <p>global count</p><p>count=count+1</p><p>…</p><p>end</p>    |
