How to add and remove elements to the table I'm iterating in
Posted: 20 May 2009, 21:45
How to add and remove elements to the table I'm iterating in:
This is more a general programming question than a Spring specific one.
I have code that goes like:
for i,e in ipairs(List) do
...
table.insert(List,...)
table.insert(List,...)
...
table.remove(List,i)
...
end
So far it seemed Lua handled it, but still, that doesn't sound very safe.
- Is Lua so good that it does magick and handle adding & removing element while iterating over a list?
- If not, what do I risk?
- What would be a sane and safe way to code this?
This is more a general programming question than a Spring specific one.
I have code that goes like:
for i,e in ipairs(List) do
...
table.insert(List,...)
table.insert(List,...)
...
table.remove(List,i)
...
end
So far it seemed Lua handled it, but still, that doesn't sound very safe.
- Is Lua so good that it does magick and handle adding & removing element while iterating over a list?
- If not, what do I risk?
- What would be a sane and safe way to code this?