小编nha*_*avt的帖子

朱莉娅的变量范围

当我在下面运行Julia代码时,出现了错误:UndefVarError: globalValue not defined.

我认为globalValue是一个全局变量,但事实并非如此.因此,如果我在for循环中添加命令"global globalValue",我的代码将起作用.那么,有谁可以看看它让我知道发生了什么?提前致谢!

globalValue = 1.0;
tempValue   = 0.1;
for ii = 1:10
    # global globalValue; if I add this command, my code will work
    tempValue = 5.0; ## I have a function to update "tempValue"
    if globalValue < tempValue
        globalValue = tempValue;
    end
end
Run Code Online (Sandbox Code Playgroud)

scope for-loop julia

9
推荐指数
1
解决办法
3257
查看次数

标签 统计

for-loop ×1

julia ×1

scope ×1