Continuing from one loop into the other?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Continuing from one loop into the other?

 
0
  #1
Aug 16th, 2008
Hi guys,

I've got two loops, and I want to be able to continue; the outermost loop when the innermost loop finds something. How would I do that?

  1. //(...)
  2. for (n = startStorage; n < quadcount; n++) {
  3. if (!notOptimized(n, optimized)) continue;
  4. int *x = &quadindex[n*4];
  5. for (eachX = 0; eachX < 4; eachX++) {
  6. if(facesPerVert[x[eachX]] > 4) continue n-loop, not eachX-loop!;
  7. //(...)

TIA,
Clockowl
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: Continuing from one loop into the other?

 
1
  #2
Aug 16th, 2008
break from the inner loop and then continue from the outer loop. If there's more to the body, you may need a flag or something similar:
  1. while (condition) {
  2. int nextIteration = 0;
  3.  
  4. while (condition) {
  5. if (condition) {
  6. nextIteration = 1;
  7. break;
  8. }
  9. }
  10.  
  11. if (nextIteration)
  12. continue;
  13.  
  14. ...
  15. }
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: Continuing from one loop into the other?

 
0
  #3
Aug 16th, 2008
It's the only way eh? Well I unrolled the loop as it's only 4 iterations, but thanks a lot for your input.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC