luyuhuang / luyuhuang.github.io

My blog
https://luyuhuang.tech
19 stars 3 forks source link

Lua next 函数的一个有趣问题 - Luyu Huang's Tech Blog #28

Open luyuhuang opened 4 years ago

luyuhuang commented 4 years ago

https://luyuhuang.tech/2020/10/23/lua-next.html

熟悉 Lua 的同学都知道, Lua 是允许在 for ... pairs 循环中修改和删除表中元素的. 下面这样的代码是没有任何问题的:local t = {a = 1, b = 2, c = 3}for k, v in pairs(t) do if v == 1 then t[k] = n...