请教一个问题,lua中类似下面这种代码可能会导致死循环吗?t ={a=100,b=200,c=3,d=4}for i, v in pairs(t) do t[v]=nil print(v)end我们的项目中用到了类似上面的代 『More』
这段代码不会。
请仔细阅读 lua 手册。 迭代 table 过程中,可以置空,但不要增加新的 key 。这一点在手册中强调过。
The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.