49 lines
845 B
Java
49 lines
845 B
Java
|
//: control/LabeledWhile.java
|
||
|
// While loops with "labeled break" and "labeled continue."
|
||
|
import static net.mindview.util.Print.*;
|
||
|
|
||
|
public class LabeledWhile {
|
||
|
public static void main(String[] args) {
|
||
|
int i = 0;
|
||
|
outer:
|
||
|
while(true) {
|
||
|
print("Outer while loop");
|
||
|
while(true) {
|
||
|
i++;
|
||
|
print("i = " + i);
|
||
|
if(i == 1) {
|
||
|
print("continue");
|
||
|
continue;
|
||
|
}
|
||
|
if(i == 3) {
|
||
|
print("continue outer");
|
||
|
continue outer;
|
||
|
}
|
||
|
if(i == 5) {
|
||
|
print("break");
|
||
|
break;
|
||
|
}
|
||
|
if(i == 7) {
|
||
|
print("break outer");
|
||
|
break outer;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} /* Output:
|
||
|
Outer while loop
|
||
|
i = 1
|
||
|
continue
|
||
|
i = 2
|
||
|
i = 3
|
||
|
continue outer
|
||
|
Outer while loop
|
||
|
i = 4
|
||
|
i = 5
|
||
|
break
|
||
|
Outer while loop
|
||
|
i = 6
|
||
|
i = 7
|
||
|
break outer
|
||
|
*///:~
|