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

What does i,v in pairs do actually do?

I have watched tutorials but they dont make sense to me

1 comment

0

If your new to that, just something I didn't get when I was new is that i and v can be any this you want, it could be for key, item in pairs (items:GetChildren()) do or anything else

1 answer

Iterator loops
Generic for loops

Call them what you want, but it's always going to be called a foreach loop to me. pairs is a generator function which takes a single table and returns next and that table you gave it. next is an iterator which can go through all of the elements in a table. I won't go into how it does it because you don't need to know because you can't even spell 'sense'.

For every time the loop runs, i,v (k,v) is set to the key and value pair for an entry in the table. This happens for every element in the table.
ipairs does a similar thing but it only goes over the array part of the table.

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