Underscore at for loops

hello fellows! im confused at this code :

for _, v ipairs(only example) do
    

so what im confused at is, why there is underscore at for loops?

your answer would be appriciated

Nothing special is going on, the _ is just a variable. It’s an easy way to show that the variable will not be used.

6 Likes

ipairs and pairs returns a key and a value for use in loops, the ipairs using an integer key, and pairs using the true key name. Most loop cases don’t need to use the key value, so a usually k or _ is used in its place.

3 Likes

_ should always be preferred over something like k for “discarding” values, as it has become the de facto (or literal way, in the case of languages such as Go) method of saying “I’m not going to use this variable.”

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.