943,544 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 533
  • C RSS
Aug 16th, 2008
0

Continuing from one loop into the other?

Expand Post »
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
Similar Threads
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Aug 16th, 2008
1

Re: Continuing from one loop into the other?

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. }
Reputation Points: 361
Solved Threads: 97
Posting Pro
Radical Edward is offline Offline
526 posts
since May 2008
Aug 16th, 2008
0

Re: Continuing from one loop into the other?

It's the only way eh? Well I unrolled the loop as it's only 4 iterations, but thanks a lot for your input.
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Connecting to SQL
Next Thread in C Forum Timeline: stack and queue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC