title: How do I properly create a loop for a user who inputted a date incorrectly?
body: <p>So, I just recently learned how to create a loop that can reiterate a particular line of code if certain criteria aren't met. After repetitive practice, I've successfully been able to use the loop with many different programs, but I've run into an issue that I can't resolve when it comes to a user inputting the wrong format for a date. Here's the code that is giving me problems:</p>
  
  <p>loop:</p>
  
  <pre><code>while(true) {
      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the Date: ");
  
      date1 = scanner.next();
  
      SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
      Date date2=null;
      try {
  
          date2 = dateFormat.parse(date1);
      } catch (ParseException e) {
          e.printStackTrace();
      }
  
      System.out.println("The date you've entered is: " + date2);
      break loop;
  }
  </code></pre>
  
  <p>When I test what happens if I enter the wrong date (say for instance I simply input the number 3) it continues to the next lines of code whilst telling me that the inputted date could not be parsed because the format was wrong. Why isn't it looping? This is the error it gives me verbatim:</p>
  
  <pre><code>java.text.ParseException: Unparseable date: "3"
  
  The date you've entered is: null
  
  Customer 1 profile:
      at java.text.DateFormat.parse(Unknown Source)
      at Creations.Shop.main(Shop.java:82)
  </code></pre>