Julia's loop scope behavior differs from Fortran?

The variable scope is each iteration of the for loop, not all iterations of the loop together.

If you want to share the variable for all iterations of the for loop, you could also (as alternative to the suggestion of @briochemc) write

local DataVar # this does not define the type of DataVar yet
for i in 1:Nloops
    if i == 1
        DataVar = 333
    end
    DataVar += 10^i
    # ...
end

Edit: It is still required to set the 1st value of DataVar, code corrected.

6 Likes