This repository was archived by the owner on Jul 12, 2023. It is now read-only.
forked from polyglot-compiler/JLang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitch.java
98 lines (92 loc) · 2.57 KB
/
Switch.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
96
97
98
public class Switch {
private static final int three = 3;
public static void main(String[] args) {
int n = 6;
label:
for (int i = 0; i < n; ++i) {
switch (i) {
case 0:
System.out.println(0);
continue label;
case 1:
case 2:
System.out.println(2);
break;
default:
System.out.println("default");
case 5:
System.out.println(5);
break;
case 4:
}
}
System.out.println("after");
// Non-integer.
byte b = 2;
switch (b) {
case 1:
System.out.println(1);
break;
case 2:
System.out.println(2);
break;
default:
}
// Unboxing.
for (Integer wrapped = 0; wrapped <= 2; ++wrapped) {
switch (wrapped) {
case 1:
System.out.println(1);
break;
case 2:
System.out.println(2);
break;
default:
System.out.println("default");
break;
}
}
// Expressions.
final int four = 4;
for (int i = -1; i <= 2; ++i) {
switch (i) {
case -1:
System.out.println(-1);
break;
case (byte) (int) 1:
System.out.println(1);
break;
case 1+1:
System.out.println(2);
break;
case three:
System.out.println(3);
break;
case four:
System.out.println(4);
break;
default:
System.out.println("default");
break;
}
}
// Switch on string.
String s = "hello";
switch (s) {
case "no":
System.out.println("no");
break;
case "hello":
System.out.println("hello");
case "fallthrough":
System.out.println("fallthrough");
break;
default:
System.out.println("default");
}
// Regression test.
switch (0) {
default: if (true);
}
}
}