Hi, I am making my own function like pairs() but doesn't work with for loop..pls tell what to do?
function mypairs(t)
for key = 0,#t do
if key == 0 then
return(next t)
elseif key >= 1 then
return(next t,key)
elseif key == #t then
break
end
end
end
Hi, I am making my own function like pairs() but doesn't work with for loop..pls tell what to do?
function mypairs(t)
for key = 0,#t do
if key == 0 then
return(next t)
elseif key >= 1 then
return(next t,key)
elseif key == #t then
break
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
is this is a troll post
I got the answer NVM and nope not a troll post
@dandystan Do you not know how pairs works? It is obviously possible to implement your own iterator.
Internally, the pairs function is this:
function pairs(t) return next, t, nil end