Digitalalias Posted March 14, 2006 Share Posted March 14, 2006 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 More sharing options...
aspnetguy Posted March 14, 2006 Share Posted March 14, 2006 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 More sharing options...
Digitalalias Posted March 14, 2006 Author Share Posted March 14, 2006 Oh ok.. I see. More work, but it accomplishes what I need. It's so funny how long code is.. the page just gets longer and longer as you try to make a smooth exit stragety. Link to comment Share on other sites More sharing options...
Webworldx Posted March 14, 2006 Share Posted March 14, 2006 Wouldn't referencing just work? <script>placer:for(i=0;i<5;i++){ for(j=0;j<3;j++){ break placer; } alert(i);}</script> ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now