If I have a simple script that sets a variable at the top level, and then tries to modify the variable from within a loop, I get an error stating that the variable is not defined:
#!/usr/bin/env julia i = 0 for j in 1:3 i = i+1 println(i, " ", j) end
~$ ./test.jl ERROR: LoadError: UndefVarError: i not defined Stacktrace:  top-level scope at /home/dortley/test.jl:5 [inlined]  top-level scope at ./none:0  include at ./boot.jl:317 [inlined]  include_relative(::Module, ::String) at ./loading.jl:1041  include(::Module, ::String) at ./sysimg.jl:29  exec_options(::Base.JLOptions) at ./client.jl:229  _start() at ./client.jl:421 in expression starting at /home/dortley/test.jl:4
If I do the same code, but wrap it in a function, I get the behavior I expect. So the following works just fine:
#!/usr/bin/env julia function go() i = 0 for j in 1:3 i = i+1 println(i, " ", j) end end go()
Is this a bug, or are we not expected to declare globals at the top level of a script like that?