Break in the WHILE circuit inside FOR LOOP
In Java, what is the direct method for exiting a WHILE loop that is inside a WHILE loop and is inside a FOR loop? The structure should look something like this:
For{
.
.
While{
.
.
.
While{
.
.
<Stuck here. Want to break Free of all Loops>;
}
}
}
use label and break
here:
while (...) {
for (...) {
if (...) break here;
}
}
see https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
Want to get out of all cycles
You can use simple break;
to end an immediate containing loop, and in Java you can use labeled
break to end an arbitrary loop. how
out: for(;;) {
while(true) {
while (true) {
// ....
break out;
}
}
}
The label is the text before :
(and the word after break
in the above example).
Note . The unlabeled break statement terminates the innermost switch, for, while, or do-while, but the unlabeled break terminates the outermost statement .
Source of note