Iterators
function ipairs(t)
local index = 0
return function()
index = index + 1
if t[index] then -- check if the value exists
return index, t[index] -- key, value
end
return nil
end
end
local t = {1, 2, 3}
for k, v in ipairs(t) do
print(k, v)
endOutput:
1 1
2 2
3 3Last updated