title: How to validate the selection menu using a loop
body: <p>Can someone edit my code to make it loop the selection menu. If the choice is not one of the 5 options it will prompt the user to re-enter until it is a valid option. If possible an explanation would be helpful as well. Thanks</p>
  
  <p>Here is my code.</p>
  
  <pre><code>import java.util.*;
  public class ShapeLoopValidation
  {
      public static void main (String [] args)
      {
          chooseShape();
      }
  
      public static void chooseShape()
      {
          while (true){
              Scanner sc = new Scanner(System.in);
              System.out.println("Select a shape number to calculate area of that shape!");
              System.out.print("Circle = 1. \nRectangle = 2. \nTriangle = 3. \nExit = 4. \nINPUT : ");
              int shapeChoice = sc.nextInt();
              //while (true) {
              if (shapeChoice &gt;= 1 &amp;&amp; shapeChoice &lt;=4)
              {
                  if (shapeChoice == 1)
                  {
                      circle();
                  }
                  else if (shapeChoice == 2)
                  {
                      rectangle();
                  }
                  else if (shapeChoice == 3)
                  {
                      triangle();
                  }
                  else if (shapeChoice == 4)
                  {
                      return;
                  }
              }
              else
              {
                  System.out.print("Error : Choice " + shapeChoice + "Does not exist.");
              }
          }
  
          class Test {
              int a, b;
  
              Test(int a, int b) {
                  this.a = a;
                  this.b = b;
              }
          }
      }
  </code></pre>