Jump to content

How to stop looping a table?


DarkLink

Recommended Posts

Posted

Guys is there a way to stop looping a table?

I mean the table have 10 elements, but I just want to loop the table for the first five, the other five wont get loaded, just ignored.

Appreciate some help guys.

Thanks.

Posted

thanks for ur reply, but look this:

  
for i,k in ipairs (getElementsByType("vehicle")) do 
   -- how do I do what is here only for the first five cars, when reach the six exit for or do nothing.. 
  
end 
  

Thanks buffalo.

Posted
for i,k in ipairs (getElementsByType("vehicle")) do 
  if i == 5 then 
      break 
  end 
end 

Posted
for i,k in ipairs (getElementsByType("vehicle")) do 
  if i == 5 then 
      break 
  end 
end 

Hmm I see so break is used to leave the for that is inside, right?

Thanks.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...