版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wowotuo/article/details/85028389
有一个error:
或
有什么问题呢?
https://discourse.julialang.org/t/undefvarerror-on-loop-iterator-in-while-loop/14747
t = 0
while t<5
println(t)
t+=1 # t = t + 1
end
提出的方案是 加global
t = 0
while t<5
println(t)
global t+=1
end
也就是在循还时,需要加一个global.
一个特例:在函数中,不需要加global.
也就是说,在非函数的脚本循还代码中,循还中的变量是不出循还的,默认是local状态。如果需要输出,需要用global.