Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.