Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What are "for i,v in pairs" and "for i,v in ipairs"? And what is their difference?

Asked by 10 years ago

I have analysed some scripts, and I found pairs and ipairs. What's the difference and how do I use them?

1 answer

Log in to vote
0
Answered by
Bebee2 195
10 years ago

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
Ad

Answer this question