I'm using Julia 1.1 and I tried to use for loop do the following simple things:
i_index=1;
for index in (1:100)
i_index=i_index+1;
end
However, I got an error saying:
ERROR: UndefVarError: i_index not defined
I have tried several times and variations, but they all failed to work. Is this a bug? or why Julia can't do this simple iterative addition?
In the REPL:
i_index=1;
for index in (1:100)
global i_index;
i_index=i_index+1;
end
This is because of variable scope, see in Julia documentation. Note that the examples there pertain to the REPL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With