Does putting for _, instead of for i, change anything?

A simple question that ive been wondering i see many people using for _, so im wondering if it changes anything.

1 Like

_ is just an identifier like any other, it has no special meaning in the language. But programmers use this to denote that they don’t intend on using this but are required to do so because some values cannot be omitted, as the order of the data is returned is based on the position. So when you see for _, v in ipairs(t) do ... end the programmer does not intend on using the index, and only cares about the value, but is required to specify an identifier, otherwise v is the index. Linters may also take this into account by not warning you about an unused variable if it’s an underscore.

4 Likes

A use case example would be if you normally type for i, v in pairs, the variable i can be used for another recursive within itself, for i, a in pairs.

1 Like