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

Can some on give me a detailed explanation of what "In Pairs" is and what it does?

Hi, I have been studying a lot about loops, I seem to understand everything, except "In Pairs". I can't find any good explanations in the wiki, so I was wondering if anyone could just spare some time to help me out.

Any help would be appreciated. Greatly.

1 comment

0

Sorry, I really don't know, but I know that i = index and v = variables, so: for "i,parts in pairs(Model)", aka index of the parts in a model (Pretty sure)

1 answer

✓ Accepted answer

Great question.

So when using a for loop you can either do

List = {1,2,3,4,5,6,7,8,9,10}

for i = 1, #List do --#List just gets the length of the list
	print(List[i])
end

this will print all of the values of the list by adding + 1 to i every time so it prints a different value every cycle.

however, if you do in pairs like so

List = {1,2,3,4,5,6,7,8,9,10}

for i, value in pairs(List) do
	print(value)
end

You will be able to actually just print value, instead of index through the List like the regular for loop.

These both will do the same thing but in some situations it is definitely better to choose one or the other.

6 comments

0

But like what is the specific purpose for In Pairs and what are some examples it could be used for so I can get a betting understanding moving forward. Apparently the first one you said isn't very good according to a lot of devs.

0

couldn't of said it better myself :)

0

You use in pairs when you want to conveniently index through an actual list/array/model/folder etc. without indexing with [i]

0

in pairs just adds on an additional 'value' to that 'i' which comes from what you put into the parenthesis after 'in pairs'

0

Oh ok, Thank you!.

0

If this helped would you mind accepting the answer? I would really appreciate it, however if it didn't help then feel free not to! :)

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