Variable scope in for loop

The relevant docs section is For Loops and Comprehensions.

What you want is:

for i = 1:2
    a = 7
    for outer i = 3
        a = 9
    end
    @show a
    @show i
end

Which gives:

a = 9
i = 3
a = 9
i = 3
1 Like