Possible Duplicate:
Breaking out of nested loops in Java
How can I use break and/or continue statements to return to the first line of the while loop at points 1, 2 and 3, for example, as indicated in the pseudocode?
Suppose I have a scenario reminiscent of the following:
while(condition) {
// want to return to this point
for (Integer x : xs) {
// point 1
for (Integer y : ys) {
// point 2
...
}
...
}
for (Integer a : as) {
for (Integer b : bs) {
// point 3
...
}
...
}
}
Use a label such as :
}
and you can then use
break outer;to escape the while loop. This works with nested for loops as well, but I try not to overuse labelsAs pointed out by @Peter, use
continue outer;if you wish to finish the current outer iteration early and continue on to the next, as opposed to escaping the while loop.