# UndefVarError: θ not defined

**URL:** <https://discourse.julialang.org/t/undefvarerror-not-defined/43820>\
**Category:** Machine Learning\
**Created:** [July 28, 2020, 3:56pm UTC](https://discourse.julialang.org/t/undefvarerror-not-defined/43820 "2020-07-28T15:56:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [July 28, 2020, 4:15pm UTC](https://discourse.julialang.org/t/undefvarerror-not-defined/43820/3 "2020-07-28T16:15:14Z")

</div>

This is due to Julia’s scoping rules, which regularly trip up beginners. Variables defined in global scope (in this case, `θ`) aren’t visible within for loops unless they’re explicitly annotated as global variables. See [here](https://discourse.julialang.org/t/tips-to-cope-with-scoping-rules-of-top-level-for-loops-etc/24902) for further discussion.

A quick example:

```julia
julia> θ = 0
0

julia> for i = 1:10
         θ += 1
       end
ERROR: UndefVarError: θ not defined
Stacktrace:
 [1] top-level scope at .\REPL[8]:2

```

```julia
julia> for i = 1:10
         global θ += 1
       end

julia> θ
10

```

---

_[View the full topic](https://discourse.julialang.org/t/undefvarerror-not-defined/43820)._
