"UndefVarError" in loop

You have to use global a inside of for.

julia> a = 5
5

julia> for i in 1:5
       global a = a + i
       end

julia> a
20

See: Another possible solution to the global scope debacle

2 Likes