Mega Code Archive
0051 Nested switch Statements
For example, the following fragment is a valid nested switch statement.
public class Main {
public static void main(String args[]) {
for (int i = 0; i < 6; i++)
switch(i) {
case 0:
switch(i+1) { // nested switch
case 0:
System.out.println("target is zero");
break;
case 1:
System.out.println("target is one");
break;
}
break;
case 2: // ...
}
}
}
The output:
target is one