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

4 comments

0

is this is a troll post

0

I got the answer NVM and nope not a troll post

0

@dandystan Do you not know how pairs works? It is obviously possible to implement your own iterator.

0

Internally, the pairs function is this: function pairs(t) return next, t, nil end