I never really understood the in pairs function, and as I get deeper into Lua, I feel like it is really useful, but I just can't understand it, can anyone help me?
COMMUNITY QUESTION
How does the in pairs function work?
1 answer
How in pairs works is that unlike a normal for loop which iterates a certain amount, it iterates through a table/array.
So let's say I have an array with five values, I would call on it like so:
local mytable = {54, 3, 9, 10}
for i, v in pairs(mytable) do
print(v)
end
The loop would print all of the values. Generic for loops like the one above are useful for iterating through an object's children effectively.
If this helped you, don't forget to accept the answer :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

8 comments
It loops through the values of a table.
https://scriptinghelpers.org/questions/100/whats-the-difference-between-a-numeric-for-loop-and-a-generic-for-loop
Yeah, but what do you mean by that
https://scriptinghelpers.org/questions/2633/what-is-pairs
https://scriptinghelpers.org/questions/4036/what-does-in-pairs-do
https://scriptinghelpers.org/questions/4751/can-somebody-explain-to-me-what-in-pairs-does-and-how-to-use-it
https://scriptinghelpers.org/questions/6544/what-does-this-meanpairs-function
Search your question before you ask it.