# Local variable inside a loop: why it ERRORs

**URL:** <https://discourse.julialang.org/t/local-variable-inside-a-loop-why-it-errors/132501>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [September 18, 2025, 11:07pm UTC](https://discourse.julialang.org/t/local-variable-inside-a-loop-why-it-errors/132501 "2025-09-18T23:07:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [September 19, 2025, 1:33pm UTC](https://discourse.julialang.org/t/local-variable-inside-a-loop-why-it-errors/132501/6 "2025-09-19T13:33:54Z")

</div>

Isn’t this in the manual:

> Note that the local scope of a for loop body is no different from the local scope of an inner function.  
> [Scope of Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#local-scope)

It’s the loop _body_ which has its own scope, so for scope purposes it’s the same as calling a function repeatedly.

---

_[View the full topic](https://discourse.julialang.org/t/local-variable-inside-a-loop-why-it-errors/132501)._
