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