# What's wrong here, why getting UndefVarError?

**URL:** <https://discourse.julialang.org/t/whats-wrong-here-why-getting-undefvarerror/20087>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 25, 2019, 12:27pm UTC](https://discourse.julialang.org/t/whats-wrong-here-why-getting-undefvarerror/20087 "2019-01-25T12:27:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 25, 2019, 12:29pm UTC](https://discourse.julialang.org/t/whats-wrong-here-why-getting-undefvarerror/20087/2 "2019-01-25T12:29:47Z")

</div>

This works:

```julia
julia> for i = 1:1000
         if i % 3 == 0 || i % 5 == 0
           global var += i
         end
       end

```

This is the global scope issue, see [Another possible solution to the global scope debacle](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894).

Also note that for speed, you need to do your computations inside a function. Where that loop will work just fine (without the `global`).

---

_[View the full topic](https://discourse.julialang.org/t/whats-wrong-here-why-getting-undefvarerror/20087)._
