What is the difference of "for i,v" and "for _, v"

i want to know the difference of i,v and _,v or if there is any difference at all

for i,v in pairs() do

for _,v in pairs() do
1 Like

Basically when you do a for loop, the i is the key and the v is the value, you can name the key and the value in any name you want, so nothing changes other than the name you need to refer those variables with.
EDIT:
For example this will do the same thing with just different names:

for key,value in pairs() do end
5 Likes

_ is often used as a variable name to indicate that it’s unused, but still needs to be there. In the for loop it’s needed because you want the second variable, the v, but two variables are returned so some other variable has to eat the first one.

It’s also used when functions return multiple values but you want the second for third one

5 Likes

When you don’t need the I, if you’re not using it, change it to _, _ means that it will not be kept in memory. If you’re doing :GetChildren() for example, the i is not needed.

It will still be kept in memory. It’s just a way for people to indicate that they will not be using it

3 Likes