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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
DarthGrover
Prole
Posts: 16
Joined: Wed Feb 05, 2014 11:31 pm
Location: Ohio USA

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

Post 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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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
Help us help you: attach a .love.
DarthGrover
Prole
Posts: 16
Joined: Wed Feb 05, 2014 11:31 pm
Location: Ohio USA

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

Post by DarthGrover »

I could make it ipairs. Thanks Robin
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests