REPL and for loops (scope behavior change)

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 least how I interpreted that), like below:

n=0
while n < 10
    println(n)
   global n+=1
end

I’m newbie in programming.

This problem is a kind of bug?

Am I doing something wrong?

Thanks since now guys!

2 Likes