How to update variables in loop in Julia 1.1.0

question
#1

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
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

0 Likes

#2

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

3 Likes