title: How to make a loop run until the console prints a certain statement within that loop?
body: <p>I am trying to achieve a certain result or output before terminating the loop. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class learnjava {
  
      public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
  
          System.out.println("How old are you?");
  
          int age = scanner.nextInt();
          scanner.nextLine();
  
          System.out.println("Do you prefer cats or dogs?");
  
          String animal = scanner.nextLine();
  
          if (age &gt; 10 || animal.equals("cats")) 
          {System.out.println("welcome!");}
          else {System.out.println("No access");}
  
      scanner.close();
          }   
  
  }
  
  </code></pre>
  
  <p>Ideally I want to create a loop that makes my code run until system prints out welcome, so that I can avoid restarting the program. I want to provide the user another chance at inputting right answers once the first input fails without running again, hence the console should ask again <em>"how old are you?"</em></p>