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

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

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.

2 comments

0

difference*

0

Sorry, I typed too fast lol

2 answers

✓ Accepted answer

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.

2 comments

0

Overkill..

0

This isn't overkill, your answer is just incomplete. :P

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