Let block in Julia

Why does this give an UndefVarError?

i = 1
println(i)
let
    println(i)
    local i = 2
    println(i)
end
println(i)

I feel like the first i appeared in let block is defined, not undefined, because if I delete the local i = 2, it works.

1 Like

Note that as documented,

The location of both the local and global keywords within the scope block is irrelevant.

See the examples.

4 Likes