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

How does the in pairs function work?

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?

8 comments

0

It loops through the values of a table.

0

Yeah, but what do you mean by that

0

Search your question before you ask it.

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.