“Switch” function in another switch function in java [closed]

You’re looking for the java feature called ‘labels’:

switch(outer) {
case 1:
    switch(inner) {
        case 1:
            break thisIsALabel;
        case 2:
    System.out.print("Hello!  ");

Calling the above with outer = 1, inner = 2 will print: Hello! Bye!. Calling it with outer = 1, inner = 1 prints just Bye!, because it is interpreted as breaking the switch statement at the same level as the label you specified, i.e. the outer ‘switch’ (a labelled break or continue breaks all constructs until you get to the targeted one, and then breaks/continues that one).

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top