-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathLabeled.java
95 lines (83 loc) · 2.45 KB
/
Labeled.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class Labeled {
public static void main(String[] args) {
stmtlabel:
System.out.println("stmtlabel");
{
System.out.println("yes");
}
blocklabel: {
if (true) break blocklabel;
System.out.println("blocklabel");
}
iflabel: if (true) {
if (true) break iflabel;
System.out.println("iflabel");
}
trylabel: try {
if (true) break trylabel;
System.out.println("trylabel");
} finally {}
switchlabel: switch (5) {
case 5: break switchlabel;
default:
System.out.println("switchlabel");
break;
}
two: labels: for (int i = 0; i < 10; ++i) {
if (i < 3) continue labels;
if (i > 3) System.out.print(' ');
System.out.print(i);
if (i > 7) break two;
}
System.out.println();
int i = 0;
doloop: do {
if (i > 0)
System.out.print(' ');
++i;
System.out.print(i);
continue doloop;
} while (i <= 5);
System.out.println();
int n = 10;
boolean x = true;
outer: while (x) {
System.out.println("inside outer");
inner: while (x) {
System.out.println("inside inner");
break outer;
}
System.out.println("no");
}
System.out.println("yes");
outer2: for (int j = 0; j < n; ++j) {
System.out.println("inside outer2");
inner2: for (int k = j + 1; k < n; ++k) {
System.out.println("inside inner2");
if (k % 2 == 0) {
continue outer2;
}
}
System.out.println("yes");
}
System.out.println("yes");
nestedLabels();
}
static void nestedLabels() {
label: while (true) {
class Inner {
void g() {
System.out.println("before inner");
label: while (true)
break label;
System.out.println("after inner");
}
}
System.out.println("before outer");
new Inner().g();
System.out.println("after outer");
break label;
}
System.out.println("after nested");
}
}