i , v in ipairs | _,v in ipairs
What is the difference between those two?
When you have a table and want to cycle through it, you have two options. ipairs(a)
and pairs(a)
. I do not know the detailed implementation of each, but what they do is that they move through a
(in this case a list) and assign values to variables. Let's focus on ipairs(a)
here. What ipairs(a)
does it returns the index and value of each entry in the key. For example, a simple loop like this:
local a = {1, 3, 4, 2} for i, j in ipairs(a) do print(i, j) end
...will print:
1 1 2 3 3 4 4 2
The thing is, many times you do not need the index, and _
is a "throwaway" variable, meaning you do not need the value assigned to it.
I don't exactly know how to explain this properly, but I think you can find a better answer here.