I have analysed some scripts, and I found pairs
and ipairs
. What's the difference and how do I use them?
ipairs is more efficient than pairs as ipairs only iterates through the number indexes until it hits a nil value of a number index.
pairs is the equivalent to next (it is, actually) as it goes through all the indexes of a table that aren't nil. It can go through string indexes.
Examples would be
local tableofstuff = {a = 5, 6, 2, boo yah = 'string'} for I,v in pairs(tableofstuff) do print(I,v) end