# How to update variables in loop in Julia 1.1.0

**URL:** https://discourse.julialang.org/t/how-to-update-variables-in-loop-in-julia-1-1-0/22554
**Category:** General Usage
**Tags:** question
**Created:** [March 30, 2019, 11:12pm UTC](https://discourse.julialang.org/t/how-to-update-variables-in-loop-in-julia-1-1-0/22554 "2019-03-30T23:12:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [March 30, 2019, 11:12pm UTC](https://discourse.julialang.org/t/how-to-update-variables-in-loop-in-julia-1-1-0/22554/1 "2019-03-30T23:12:49Z")

</div>

Dear All,

how can we update the variable s in loop in Julia?

```julia

  un = zeros(Float64,3,1)
    an1 = zeros(Float64,3,1)
for n in 1 : 3
    an1 = un
    un = an1
end

```

`ERROR: LoadError: UndefVarError: un not defined`

I know that the solution is add global to un (

> global un = an1

),  
but is there another method that we can use to fix this bug in Julia 1.1.0?

Best

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 30, 2019, 11:28pm UTC](https://discourse.julialang.org/t/how-to-update-variables-in-loop-in-julia-1-1-0/22554/2 "2019-03-30T23:28:28Z")

</div>

If you want to update global variables then use `global`. However, the recommended way is to write functions and not use globals like this.
