So i very recently learned the for i,v in pairs loop and ive seen some people doing "for i,v in ipairs" instead of "for i,v in pairs"? What's the difference?
So basically for i,v in pairs
will go through an entire table, and do whatever it's asked to. But for i,v in ipairs
has a twist. It stops when it reaches a nil
value. For example:
local myTable = {1,2,nil,3} for i,v in pairs(myTable) do print(v) end
This would output:
1 2 3
But if we did:
local myTable = {1,2,nil,3} for i,v in ipairs(myTable) do print(v) end
Would only output:
1 2
Because it stops at the nil value
Locked by User#19524
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?