title: Exit while loop in java that has switch case?
body: <p>I have a simple problem, I wrote switch case inside while loop that has 5 cases.</p>
  
  <p>My program should keep working all the time, but when i enter 5 the program should exit.</p>
  
  <p>here is my code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Test3 {
  
  public static void main(String argv[])
  {
      Scanner input = new Scanner(System.in);
      System.out.println("1. Add Product");
      System.out.println("2. Edit Product");
      System.out.println("3. Delete Product");
      System.out.println("4. Search Product");
      System.out.println("5. Exit Application");
      int choice = input.nextInt();
      int i = 1;
      while(i == 1)
      {
      switch(choice)
      {
          case 1:
              System.out.println("Add");
              break;
          case 2:
              System.out.println("Edit");
              break;
          case 3:
              System.out.println("Delete");
              break;
          case 4:
              System.out.println("Search");
              break;
          case 5:
              i = 2;
              break;
          default:
              System.out.println("Invalid Choice .. Try Again.");
      }
      }
  }
  
  }
  </code></pre>
  
  <p>The problem is when i use one of the 4 cases. for example if i enter 1 ... the program keep printing (Add) infinite ... i want to use case only one time then back again to the program to either enter another case or exit.</p>