> 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.1-local-variables.md).

# 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.&#x20;

### Example&#xD;

“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.&#x20;

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 | <p>var main\_v=10 |

</p><p>var x=3</p><p>call 107</p><p>print main_v  # ok</p><p>print sub_v  # error</p><p>print x # 3 is printed</p><p>end</p> |
| 0107.job | <p>var sub_v=20</p><p>var x</p><p>print sub_v  # ok</p><p>print main_v  # error</p><p>x=5</p><p>end</p>                                        |
