Java我不明白为什么在更改switch语句的顺序时会得到不同的输出

Mr.*_*tic 1 java

我写的时候:

System.out.println("[move,new,restart,hint,solve,quit]>");
            String input = in.next();
            switch (input){
                case "restart":
                    System.out.println("You chose restart");
                    continue;
                case "quit"://Quits out of the program
                    cont = false;
                default:
                    break;
            }
            System.out.println("here");
Run Code Online (Sandbox Code Playgroud)

我得到输出:

[move,new,restart,hint,solve,quit]>
restart
You chose restart
[move,new,restart,hint,solve,quit]>
quit
here
Run Code Online (Sandbox Code Playgroud)

但当我切换case语句重启并退出时,我收到了不同的输出:我的代码:

System.out.println("[move,new,restart,hint,solve,quit]>");
            String input = in.next();
            switch (input){
                case "quit"://Quits out of the program
                    cont = false;
                case "restart":
                    System.out.println("You chose restart");
                    continue;

                default:
                    break;
            }
            System.out.println("here");
Run Code Online (Sandbox Code Playgroud)

我得到输出:

[move,new,restart,hint,solve,quit]>
restart
You chose restart
[move,new,restart,hint,solve,quit]>
quit
You chose restart
Run Code Online (Sandbox Code Playgroud)

我很难理解为什么case语句的顺序会影响输出.

T M*_*own 5

break;的"退出"逻辑错过了您的案例

switch (input){
            case "quit"://Quits out of the program
                cont = false;
                break;
            case "restart":
                System.out.println("You chose restart");
                continue;

            default:
                break;
        }
Run Code Online (Sandbox Code Playgroud)