Something to keep in mind: while is a “soft” scope. “Soft” just means its scoping rules on accessing global variables is different in interactive contexts (REPL, notebooks) versus non-interactive ones (.jl scripts, eval-ed expressions).
You can check script behavior really quick this way: