Others mentioned how you can set a flag or use goto , but I would recommend refactoring your code so that the inner loop is turned into a separate method. This method can then return some flag to indicate that the outer loop should break . If you name your methods accordingly, it will be more readable.
for (int i = 0; i < 10; i++) { if (timeToStop(i)) break; } -(bool) timeToStop: (int) i { for (int j = 0; j < 10; j++) { if (somethingBadHappens) return true; } return false; }
Pseudocode, not tested, but you understand the idea.
Caffeine Coma May 14, '09 at 1:59 pm 2009-05-14 13:59
source share