# "UndefVarError" in loop

**URL:** <https://discourse.julialang.org/t/undefvarerror-in-loop/19757>\
**Category:** New to Julia\
**Created:** [January 17, 2019, 7:53pm UTC](https://discourse.julialang.org/t/undefvarerror-in-loop/19757 "2019-01-17T19:53:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [January 17, 2019, 8:00pm UTC](https://discourse.julialang.org/t/undefvarerror-in-loop/19757/2 "2019-01-17T20:00:25Z")

</div>

You have to use `global a` inside of `for`.

```julia
julia> a = 5
5

julia> for i in 1:5
       global a = a + i
       end

julia> a
20

```

See: [Another possible solution to the global scope debacle](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894)

---

_[View the full topic](https://discourse.julialang.org/t/undefvarerror-in-loop/19757)._
