What is the difference between these two loops and when should one be favored over the other?
for i, v in pairs (items) do
end
--vs
for i = 1, #items do
end
What is the difference between these two loops and when should one be favored over the other?
for i, v in pairs (items) do
end
--vs
for i = 1, #items do
end
Use for i, v when you want to do something with the objects and data inside the table while looping through them.
As for the second one, why does it even exist, it work if u wanna loop something for #items amount, but why tho, for i, v can do the same thing.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
That's why I was asking the question in the first place because why would you use the second one when you have the first one? I guess maybe it uses less data because it doesn't label the index and only gets the value?