954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Continuing from one loop into the other?

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?

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


TIA,
Clockowl

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

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:

while (condition) {
  int nextIteration = 0;

  while (condition) {
    if (condition) {
      nextIteration = 1;
      break;
    }
  }

  if (nextIteration)
    continue;

  ...
}
Radical Edward
Posting Pro
545 posts since May 2008
Reputation Points: 361
Solved Threads: 97
 

It's the only way eh? Well I unrolled the loop as it's only 4 iterations, but thanks a lot for your input. :)

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You