It prints i= 5 when run, can you help me understand why it prints 5. also, case 'c'|'d' : is unreachable. it dosen't print anything for that.
var ca = new char[]{'a', 'b', 'c', 'd'};
var i = 0;
for (var c : ca) {
switch (c) {
case 'a':
i++;
System.out.println("Case a : " + c + " : " + i);
case 'b':
++i;
System.out.println("Case b: " + c + " : " + i);
case 'c'|'d' :
i++;
System.out.println("Case c or d : "+c + " : "+i);
}
The code shows following output.
Case a : a : 1
Case b: a : 2
Case c or d : a : 3
Case b: b : 4
Case c or d : b : 5
5
it means, in array, 3rd and 4th elements were never processed. Why??