title: Rerun main method if an invalid response is given?
body: <p>So I made this rock paper scissors game a while ago using Java and I found a little bug I forgot to fix when I showed it to my friend today. Basically, the code takes a user input (i.e rock, paper, or scissors) and if their input does not equal rock, paper, or scissors, the main <em>while</em> loop is broken and the game is stopped. </p>
  
  <p><strong>How can I make it so that not only does it break the loop, but restarts it as well?</strong> I want to do this so that when someone gives an invalid input it automatically restarts so the player doesn't need to run the program all over again.</p>
  
  <p>Here's the code for my <em>main</em> class:</p>
  
  <pre><code>public class rps {
      public static void main(String []args){
          boolean gameRunning = true;
          while(gameRunning) {
              System.out.println("Do you choose rock, paper, or scissors?");
              UserChoice userInput = new UserChoice();
              String userChoice = userInput.userDecide();
              if(userChoice != "rock" || userChoice != "paper" || userChoice != "scissors") {
                  System.out.println("'" + userChoice + "'" + " is not a valid choice.");
                  System.out.println("Please choose between rock, paper, or scissors.");
                  gameRunning = false;
                  break;
                  // this is where I want to restart the function 
              }
              System.out.println("You threw: " + userChoice);
              ComputerInput computerChoice = new ComputerInput();
              String computerInput = computerChoice.computerDecide();
              System.out.println("Computer threw: " + computerInput);
              CompareChoices compareResults = new CompareChoices();
              gameRunning = compareResults.compare(userChoice, computerInput);
          }
      }
  };
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I figured out a few of the problems thanks to some help from the nice people on here. I used &amp;&amp; instead of || (which is dumb because I originally used &amp;&amp; anyways -_-), I used the "continue" statement instead of break, I removed <code>gameRunning = false;</code>, and I changed the way <code>userChoice</code> was compared to the valid responses.</p>
  
  <p>Instead of comparing it to Strings like "rock" and "paper", I created an array
  (<code>String validChoices[] = {"rock", "paper", "scissors"};</code>) which holds the valid responses. Then I compared <code>userChoice</code> to the indices of the array.</p>
  
  <p>Here is my new code:</p>
  
  <pre><code>public class rps {
   public static void main(String []args){
        boolean gameRunning = true;
        while(gameRunning) {
            System.out.println("Do you choose rock, paper, or scissors?");
            UserChoice userInput = new UserChoice();
            String userChoice = userInput.userDecide();
            String validChoices[] = {"rock", "paper", "scissors"};
              if(!userChoice.equals(validChoices[0]) &amp;&amp; !userChoice.equals(validChoices[1]) &amp;&amp; !userChoice.equals(validChoices[2])) {
                  System.out.println("'" + userChoice + "'" + " is not a valid choice.");
                  System.out.println("Please choose either rock, paper, or scissors.");
                  continue;
              }
            System.out.println("You threw: " + userChoice);
            ComputerInput computerChoice = new ComputerInput();
            String computerInput = computerChoice.computerDecide();
            System.out.println("Computer threw: " + computerInput);
            CompareChoices compareResults = new CompareChoices();
            gameRunning = compareResults.compare(userChoice, computerInput);
        }
   }
  </code></pre>
  
  <p>};</p>
  
  <p>Thanks everyone!</p>