The problem is that (global a+=1 for i in 1:3) creates a “generator” which goes through the loop lazily, ie at a later point when you call collect or iterate through it. You can just do [global a+=1 for i in 1:3] to run the loop immediately.

Along the lines @isaacsas suggestion, here is my temporary suggestion:

Use Jupyter for most interactive use for now

When you are in the REPL or in a julia script, never use loops or control structures relying on scope rules outside of a function. This will not be a major inconvenience in the short-term.

If you do this, the scoping behavior will be exactly the sort of thing you have in mind (i.e., you won’t need to think about global scope issues, never need to type global under normal circumstances, and can copy/paste code between functions and jupyter).

Finally, have faith that some variation of Another possible solution to the global scope debacle will be implemented when it is ready and tested, then you can start using loops again outside of functions/jupyter, and you probably won’t need to think about this stuff again.