Can Java handle nested switch statements?

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;

    case 0: System.out.println("i is 0"); break;
    case 1: System.out.println("i is 1");
        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");

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact