UndefVarError on loop iterator in while loop

When I try to run this code I copied from a tutorial, I get an error.

t = 0
while t<5
    t+=1 # t = t + 1

LoadError: UndefVarError: n not defined
Did I do something wrong while setting up Julia?

1 Like

In short, in global scope, you would need global t += 1 instead since you are modifying a global variable. In a function, your code would work as is.

See https://github.com/JuliaLang/julia/issues/28789 for some discussion about this.


Which one? Might be a good idea to update this for Julia v1.0.

I got the same issue. This code can be found here: https://github.com/JuliaComputing/JuliaBoxTutorials/blob/master/introductory-tutorials/intro-to-julia/04.%20Loops.ipynb
andin the youtube tutorial: https://www.youtube.com/watch?v=4igzy3bGVkQ