Can Java handle nested switch statements?
Created May 25, 2006
Byron Tymvios
Nested switch statements are allowed. Just make sure you remember to have all the break statements in the correct places. E.g:
int i;
int j;
switch(i){
case 0: System.out.println("i is 0"); break;
case 1: System.out.println("i is 1");
switch(j){
case 0: System.out.println("j is 0"); break;
case 1: System.out.println("j is 1"); break;
default: System.out.println("j is not known");
} break; //note this break after 2nd switch
default: System.out.println("i is not known");
}