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

Recommended Answers

All 2 Replies

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;

  ...
}
commented: Simple clean example. +1

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.