title: Scanner input validation in while loop
body: <p>I've got to show Scanner inputs in a <strong>while</strong> loop: the user has to insert inputs until he writes "quit". So, I've got to validate each input to check if he writes "quit". How can I do that?</p>
  
  <pre><code>while (!scanner.nextLine().equals("quit")) {
      System.out.println("Insert question code:");
      String question = scanner.nextLine();
      System.out.println("Insert answer code:");
      String answer = scanner.nextLine();
  
      service.storeResults(question, answer); // This stores given inputs on db
  }
  </code></pre>
  
  <p>This doesn't work. How can I validate each user input?</p>