I realise this is old and tired. I disagreed with the scope changes of 1.5, but I am not trying to open that discussion. I am just genuinely puzzled by the following in the REPL:
for outer = 1:2
println("outer = $outer before inner loop")
for inner = 11:12
outer = outer + 7
println(inner + outer)
end
println("outer = $outer after inner loop")
end
outer = 1 before inner loop
19
27
outer = 15 after inner loop
outer = 2 before inner loop
20
28
outer = 16 after inner loop
I know that the line outer = outer + 7 does not throw a warning because outer, while not local to the inner loop, is not a global variable either. What puzzles me is that the assignment in the inner loop first persists, hence the outer = 2 before inner loop that appears as a result of println(outer) after after the first pass through the inner loop.
What puzzles me is that returning to the top of the code body of the first loop, outer is again determined by the sequence defined by the specification of the loop values. I guess effectively there is another assignment, and that a hidden variable keeps track of what the actual value of outer should be at the start of each pass through the outer loop, and that this value is assigned to outer at that point, undoing whatever may have been assigned to outer during the rest of the pass through the outer loop (including of course all passes through the inner loop).
Have I got it right? And if so, where is this immutability of the sequence if loop values documented (apologies again for asking, I seem to remember it is documented but I don’t remember where)?