Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
AyeJude 41
6 years ago

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.

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) iiDoge_Legend 3 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

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. AyeJude 41 — 6y
0
couldn't of said it better myself :) User#19524 175 — 6y
0
You use in pairs when you want to conveniently index through an actual list/array/model/folder etc. without indexing with [i] PoePoeCannon 519 — 6y
0
in pairs just adds on an additional 'value' to that 'i' which comes from what you put into the parenthesis after 'in pairs' PoePoeCannon 519 — 6y
View all comments (2 more)
0
Oh ok, Thank you!. AyeJude 41 — 6y
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! :) PoePoeCannon 519 — 6y
Ad

Answer this question