Cory Bloyd
2005-09-22 15:39:29 UTC
What happens when you modify a table while iterating over it?
I would expect the following iteration to proceed unaffected by the
modifications, but I'm not certain...
for key, value in pairs(someTable) do
if someArbitraryCondition() then
someTable[key] = nil
end
end
I would expect the following code to behave unpredictably regarding
whether or not the new items appear in the iteration.
for key, value in pairs(someTable) do
if someArbitraryCondition() then
someTable[newKey()] = newValue()
end
end
Can anyone confirm or deny my suspicions?
I would expect the following iteration to proceed unaffected by the
modifications, but I'm not certain...
for key, value in pairs(someTable) do
if someArbitraryCondition() then
someTable[key] = nil
end
end
I would expect the following code to behave unpredictably regarding
whether or not the new items appear in the iteration.
for key, value in pairs(someTable) do
if someArbitraryCondition() then
someTable[newKey()] = newValue()
end
end
Can anyone confirm or deny my suspicions?