Page 1 of 1

how to do gen for loop starting at a given point?

Posted: Mon Mar 10, 2014 4:04 pm
by DarthGrover
If I am looping through i,v in pairs in a table and want to compare v to all the remaining v s how do I write a sub loop that begins with the next item in the table and goes to the end?

Re: how to do gen for loop starting at a given point?

Posted: Mon Mar 10, 2014 4:13 pm
by Robin
Do you mean pairs or ipairs? If the latter:

Code: Select all

for i, v in ipairs(t) do
   for j = i + 1, #t do
       -- do your thing with i, v, j and t[j]
   end
end

Re: how to do gen for loop starting at a given point?

Posted: Mon Mar 10, 2014 5:00 pm
by DarthGrover
I could make it ipairs. Thanks Robin