I came across something rather interesting today and was curious if someone could shed some light as to what the difference is. I’ve been primarily using Jupyter Lab and haven’t come across this issue before until now when I started a new script today. I’m finding that:
a = 0 for i=1:3 a += 1 end println(a)
will fail, whereas
a = 0 for i=1:3 global a += 1 end println(a)
function b() a = 0 for i=1:3 a += 1 end println(a) end b()
both work as expected. Why is there this difference? I have looked at this thread. For simple scripts, I guess I’m not sure why I need to make this distinction- part of the beauty of Julia for me is that speed can be optional, when convenience is nice. In this example, it’s not a big deal.
Thanks for your insight in advance.