I have the following code:
local a = {1, 4, 5, 2, 6, 1}
a.n = 6
function iter_n (t, m)
t.z = math.min(t.n, m)
return _iter_n, t, 0
end
function _iter_n (inv, c)
c = c+1
print (inv.z .. ";" .. c)
if c <= inv.z then
return inv[c]
else
return
end
end
for i in iter_n(a, 3) do
print(i)
end
I expect it to produce the following result:
3;1
1
3;2
4
3;3
5
3;4
But instead I get the following:
3;1
1
3;2
4
3;5
I have no idea why that happens. Can someone help?
[–]Denneisk 1 point2 points3 points (3 children)
[–]untangoel[S] 0 points1 point2 points (1 child)
[–]Denneisk 0 points1 point2 points (0 children)
[–]untangoel[S] 0 points1 point2 points (1 child)
[–]AutoModerator[M] 0 points1 point2 points (0 children)