2015-04-20 15:36:01 -07:00
|
|
|
|
//: control/LabeledWhile.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// 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
|
|
|
|
|
*///:~
|