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

Is there a difference between for _,v in pairs() and for i,v in pairs() ?

Asked by 7 years ago
Edited 7 years ago

Is there a difference between for _,v in pairs() and for i,v in pairs() ?

Just something I wanted to finally figure out with some help.

I havent found anything on the wiki yet.

0
difference* RubenKan 3615 — 7y
0
Sorry, I typed too fast lol iiParadoxLegacy 38 — 7y

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

There is technically no difference, as _, v, and i in both of the examples are just variables used to catch the return values of the pairs call(s). _ is a valid variable name, after all.

However, there is a semantic difference: _ is meant as a placeholder. Specifically, it denotes a variable you never intend to use. In the case of for _, v in pairs(tab) do it implies that we don't care about the indices of the table we're traversing, only the values.

This is relatively uncommon practice, as almost every function call you make should return the more relevant stuff first, but, as with pairs and ipairs, it does come up on occasion.

0
Overkill.. RubenKan 3615 — 7y
0
This isn't overkill, your answer is just incomplete. :P adark 5487 — 7y
Ad
Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago

there's no difference.

Answer this question