I'm trying to understand the scope rules in Julia. I've tried a for loop with z as a regular integer variable:
z = 2
for i = 1:4
z += 1
end
println(z)
and it gives me an UndefVarError: z not defined error, unless I put global z inside of the loop.
However, if I make z a 1x1 array it works perfectly fine without global:
z = [2]
for i = 1:4
z .+= 1
end
println(z)
$ julia test.jl
[6]
What's the difference between scopes of arrays and variables?