Hi all,

Near the top of the variables and scoping chapter of the documentation, 
there's a list which is kicked off by, "These constructs which introduce 
new variables into the current scope are as follows:"). How could this be 
worded to express things the other way round --- that is, "When assigning 
to a variable, you *usually* create a new local; the only times you don't 
are when: ..."?

My understanding thus far is: when assigning to a variable, the only times 
you *don't* create a new local is when you're assigning to an already 
existing outer local or outer global. Is that the case?

Finally then, if that's the case, what is going on here:

~~~julia
#!/usr/bin/julia

n = 1  # top-level variable, aka global

while n <= 3
    println(n)
    # Wait. We're assigning here within the `while` scope... Though it would
    # be weird, shouldn't that make a new local `n` since we don't have 
`global n`
    # written anywhere in this scope?
    n = n + 1
end

# prints 1 2 3

println("done, and now n = ", n)  # prints 4
~~~

Thanks,
-- John

Reply via email to