# Variable scope in while loops

**URL:** <https://discourse.julialang.org/t/variable-scope-in-while-loops/15886>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 4, 2018, 3:17pm UTC](https://discourse.julialang.org/t/variable-scope-in-while-loops/15886 "2018-10-04T15:17:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 4, 2018, 3:25pm UTC](https://discourse.julialang.org/t/variable-scope-in-while-loops/15886/2 "2018-10-04T15:25:50Z")

</div>

You need a `global a` in the `while` loop.

See also [https://github.com/JuliaLang/julia/issues/28789](https://github.com/JuliaLang/julia/issues/28789) and [Global variables not visible within loops in scripts](https://discourse.julialang.org/t/global-variables-not-visible-within-loops-in-scripts/15849) … this behavior is slated to be changed in interactive contexts. In IJulia/Jupyter it is already changed.

---

_[View the full topic](https://discourse.julialang.org/t/variable-scope-in-while-loops/15886)._
