Jump to content

Breaking a Nested Loop?


Digitalalias

Recommended Posts

Hi All,To my surprise, the search I did on "nested loop" didn't bring up anything. My question is how do I break a nested loop. I've seen it before but I forget what the syntax is. I think it's this

for() { . .  for() {  .   .  break; break; }}

I know that just doing one break will get you out of that 2nd loop, but what about the 1st loop. Thanks for any help.

Link to comment
Share on other sites

You could use something like this

var i;var j;var is_broken = false;for(i=0i<10;i++){   for(j=0;j<10;j++)   {      if(some condition)      {         is_broken = true;         break;      }   }      if(is_broken)   {      break;   }}

Link to comment
Share on other sites

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
×
×
  • Create New...