# Problem in variable definition in loop

**URL:** <https://discourse.julialang.org/t/problem-in-variable-definition-in-loop/19752>\
**Category:** New to Julia\
**Created:** [January 17, 2019, 6:04pm UTC](https://discourse.julialang.org/t/problem-in-variable-definition-in-loop/19752 "2019-01-17T18:04:07Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 18, 2019, 2:28pm UTC](https://discourse.julialang.org/t/problem-in-variable-definition-in-loop/19752/11 "2019-01-18T14:28:52Z")

</div>

The not-so-obvious scoping rules you see has been discussed quite a bit over the last year or so. It’s a contentious issue and as far as I am aware, no solution was agreed upon.

> [@REPL and for loops (scope behavior change)](https://discourse.julialang.org/t/repl-and-for-loops-scope-behavior-change/13514/7):
>
> Hi Guys, i’m having the same problem in Jupyter Notebook. I’m creating my own Julia tutorial following the youtube “Intro to Julia” video. In a code cell I made it: n=0 while n \< 10 println(n) n+=1 end And the result was: UndefVarError: n not defined Stacktrace: [1] top-level scope at ./In[18]:3 [inlined] [2] top-level scope at ./none:0 I’ve tried to put the local status in any place but the result still goes wrong, the solution came following @saschatimme instructions (or at leas…

> [@REPL and for loops (scope behavior change)](https://discourse.julialang.org/t/repl-and-for-loops-scope-behavior-change/13514/8):
>
> It is not a bug. It worked in Julia 0.6, in Julia 0.7 it gave a deprecation warning that you must add global, and in 1.0 it throws an error. I really like favba’s idea of starting by introducing functions and teaching them to write tiny functions. Sounds like that’d also end up encouraging good coding habits.

And many more threads.

---

_[View the full topic](https://discourse.julialang.org/t/problem-in-variable-definition-in-loop/19752)._
