How to update variables in loop in Julia 1.1.0

Dear All,

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

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

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?


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