# Global scope confusion again

**URL:** <https://discourse.julialang.org/t/global-scope-confusion-again/20044>\
**Category:** General Usage\
**Tags:** question, scope\
**Created:** [January 24, 2019, 5:08pm UTC](https://discourse.julialang.org/t/global-scope-confusion-again/20044 "2019-01-24T17:08:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [January 24, 2019, 5:18pm UTC](https://discourse.julialang.org/t/global-scope-confusion-again/20044/2 "2019-01-24T17:18:50Z")

</div>

`a` is a global variable in the REPL and must be annotated inside the loop as such, to avoid this, insert your code inside a function. See this discussion for more information: [REPL and for loops (scope behavior change)](https://discourse.julialang.org/t/repl-and-for-loops-scope-behavior-change/13514).

```julia
julia> function test()
           a = 1.0
           b = 1.0
           e = 0.1
           for i in 1:5
               x = a - e*b
               y = b + e*a
               println(i," “,x,” ",y)
               a = x
               b = y
           end
       end
test (generic function with 1 method)

julia> test()
1 “,x,” 1.1
2 “,x,” 1.1900000000000002
3 “,x,” 1.2690000000000001
4 “,x,” 1.3361
5 “,x,” 1.3905100000000001

```

---

_[View the full topic](https://discourse.julialang.org/t/global-scope-confusion-again/20044)._
