How to stop two for?

Hey I’m trying to stop 2 for but when I use break it only stop the secound for but the first for stars again

for i = 0, 4, 1 do  
 for y = 0, 6, 1 do  
 if y == 3 then  
 break  
 end  
  
 print(y)  
 end  
end  

this is what the terminal shows

2012-12-11 14:30:36.222 Corona Simulator[55149:f03] 0  
2012-12-11 14:30:36.223 Corona Simulator[55149:f03] 1  
2012-12-11 14:30:36.223 Corona Simulator[55149:f03] 2  
2012-12-11 14:30:36.227 Corona Simulator[55149:f03] 0  
2012-12-11 14:30:36.227 Corona Simulator[55149:f03] 1  
2012-12-11 14:30:36.231 Corona Simulator[55149:f03] 2  
2012-12-11 14:30:36.231 Corona Simulator[55149:f03] 0  
2012-12-11 14:30:36.232 Corona Simulator[55149:f03] 1  
2012-12-11 14:30:36.232 Corona Simulator[55149:f03] 2  
2012-12-11 14:30:36.233 Corona Simulator[55149:f03] 0  
2012-12-11 14:30:36.233 Corona Simulator[55149:f03] 1  
2012-12-11 14:30:36.234 Corona Simulator[55149:f03] 2  
2012-12-11 14:30:36.234 Corona Simulator[55149:f03] 0  
2012-12-11 14:30:36.234 Corona Simulator[55149:f03] 1  
2012-12-11 14:30:36.234 Corona Simulator[55149:f03] 2  

anyone can tell me how to stop this two for when the first y == 3 is fired ? [import]uid: 23063 topic_id: 33870 reply_id: 333870[/import]

Maybe use a bool to stop the whole thing.

local breakAllLoops = false  
for i = 0, 4, 1 do  
  
 if breakAllLoops then  
 break  
 end  
  
 for y = 0, 6, 1 do  
  
 if breakAllLoops then  
 break  
 end  
  
 if y == 3 then  
 breakAllLoops = true  
 break  
 end  
  
 print(y)  
 end  
end  
  

It’s a bit ugly, but should work [import]uid: 84115 topic_id: 33870 reply_id: 134632[/import]

Thaanks, this works! :smiley: [import]uid: 23063 topic_id: 33870 reply_id: 134633[/import]

Glad to hear.
Out of interest, was this just for you to test out how ‘break’ works? I’m struggling to see why the second for loop goes up to 6 if you want it to break at 3. [import]uid: 84115 topic_id: 33870 reply_id: 134634[/import]

I’m doing an TD game that check hit box for collisions and I’m trying to make a gameover when the enemies hit an object

so when the enemies hit this object I will call an function to make the gameover of my game and I need stop this testing of hit box after gameover’s function is called

don’t know if you understand what i’m trying to do… besides my english isn’t so good :T

sorry any misstake

thanks [import]uid: 23063 topic_id: 33870 reply_id: 134637[/import]

Maybe use a bool to stop the whole thing.

local breakAllLoops = false  
for i = 0, 4, 1 do  
  
 if breakAllLoops then  
 break  
 end  
  
 for y = 0, 6, 1 do  
  
 if breakAllLoops then  
 break  
 end  
  
 if y == 3 then  
 breakAllLoops = true  
 break  
 end  
  
 print(y)  
 end  
end  
  

It’s a bit ugly, but should work [import]uid: 84115 topic_id: 33870 reply_id: 134632[/import]

Thaanks, this works! :smiley: [import]uid: 23063 topic_id: 33870 reply_id: 134633[/import]

Glad to hear.
Out of interest, was this just for you to test out how ‘break’ works? I’m struggling to see why the second for loop goes up to 6 if you want it to break at 3. [import]uid: 84115 topic_id: 33870 reply_id: 134634[/import]

I’m doing an TD game that check hit box for collisions and I’m trying to make a gameover when the enemies hit an object

so when the enemies hit this object I will call an function to make the gameover of my game and I need stop this testing of hit box after gameover’s function is called

don’t know if you understand what i’m trying to do… besides my english isn’t so good :T

sorry any misstake

thanks [import]uid: 23063 topic_id: 33870 reply_id: 134637[/import]