当我在下面运行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)