Did I miss the mention on what language we are talking about here??
The method is the same whether the loops are infinite or not. As George said, to early exit from a loop requires an if statement to check a desired condition and if the condition is true, whatever statement is required for the particular language to get out of the loop.
In C/C++, the early exit statement is 'break'.
if (doneEarly == TRUE) {
break;
}
Also, agreeing with Rolos, nested infinite loops don't make sense. Consider an infinite loop with a nested infinte loop, neither with early exit statements. The outer loop will start and then the inner loop will start and the inner loop will run infinitely, so the outer loop will never move on to it's second iteration, because the inner loop never completes, so what is the point of the outer loop?
Now, move on to the case where the inner loop has an early exit check. My original thinking was to say that if the inner loop had an early exit check, then why not just make the early exit check the loop condition?
But, I suppose there could be a situation where you have a long inner loop and the early exit check 'fits' in the middle of the loop rather than at the end, so making it the loop condition would be 'inconvenient'.
But, I think that I'd still recode it so that it's the loop condition rather than having two infinite loops. This way, when someone else looks at the code, it'll be more obvious how you exit the inner loop.