title: Java How can I break a while loop under a switch statement?
body: <p>I have a homework to implement a simple testing application, below is my current code:</p>
  
  <pre><code>import java.util.*;
  
  public class Test{
  
  private static int typing;
  
  public static void main(String argv[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Testing starts");
      while(sc.hasNextInt()){
          typing = sc.nextInt();
          switch(typing){
              case 0:
                break; //Here I want to break the while loop
              case 1:
                System.out.println("You choosed 1");
                break;
              case 2:
                System.out.println("You choosed 2");
                break;
              default:
                System.out.println("No such choice");
          }
      }
        System.out.println("Test is done");
      }
  }
  </code></pre>
  
  <p>What I want to do now is that when <code>0</code> is pressed, it means that the user wants to quit the test, then I break the <code>while loop</code> and print <code>Test is done</code>, but it doesn't work like that, I know the reason might be that the <code>"break"</code> breaks the <code>switch</code>, how can I let it break the <code>while loop</code> instead?</p>