闭包实现迭代器
function list_iter(t)local i = 0local n = table.getn(t)return function()i = i + 1if i <= n then return t[i] endend
endt = {10, 20, 30}
iter = list_iter(t)
while true dolocal element = iter()if element == nil then break endprint(element)
end
?
轉載于:https://www.cnblogs.com/zzyoucan/p/5891122.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: 实训七(项目准备与创建)
- 下一篇: 实训九(游戏退出按钮的实现)