title: How to repeat a loop after the loop has been finished
body: <p>I am doing an assignment that asks to create a guessing game but I have already coded the guessing game. I need to ask the user if they want to play the guessing game again in which I need to re-trigger the loop. I am not sure how to re-trigger after the first loop as already been executed and finished.</p>
  
  <p>Here is my code for the Guessing game:</p>
  
  <pre><code>import java.util.Random;
  import java.util.Scanner;
  public class ThreeEleven
  {
  
  
   public static void main (String[] args)
      {
  final int MAX = 100;
  int answer, guess;
  String again;
  Scanner scan = new Scanner(System.in);
  System.out.print ("I'm thinking of a number between 1 and "
  + MAX + ". Guess what it is: (or enter 0 to quit) ");
  guess = scan.nextInt();
  
  Random generator = new Random(); //Random generator. 1 to 100.
  answer = generator.nextInt(MAX) +1;
  
      //if (guess == answer){ //If guess equals answer
          //System.out.println ("You got it! Good guessing!");
  
      //}
      //else if (guess == 0){ //Game ends
          //System.out.println ("You have ended your game. Goodbye.");
  
      //}
  
          while (guess != answer &amp;&amp; guess != 0){ //If guess and 0 is not answer, continue.
  
              if (guess &gt; answer &amp;&amp; guess != 0){ //If guess is higher than answer
                  System.out.println ("You guessed too high!");
                  guess = scan.nextInt();
  
              }
              else{
                  if (guess &lt; answer &amp;&amp; guess != 0){ //If guess is lower than answer
                      System.out.println ("You guessed too low!");
                      guess = scan.nextInt();
                  }
  
                  else if (guess == answer){ //If guess equals answer
                      System.out.println ("You got it! Good guessing!");
                  }
                  else if (guess == 0){ //Game ends
                      System.out.println ("You have ended your game. Goodbye.");
                  }
                      }
  }
          if (guess == answer){
              System.out.println ("You got it! Good guessing!");
             //System.out.println ("You guessed " +  + " times");
  
   //  System.out.println ("Want to play again? (yes or no)?");
         // again = scan.next();
        //  if (again == "yes")
       //   {
             // System.out.print ("I'm thinking of a number between 1 and "
  
  
  // + MAX + ". Guess what it is: (or enter 0 to quit) ");
      //guess = scan.nextInt();
             // while (again == "yes")
             // {
             // while (guess != answer &amp;&amp; guess != 0){ //If guess and 0 is not answer, continue.
  
            // if (guess &gt; answer &amp;&amp; guess != 0){ //If guess is higher than answer
                //  System.out.println ("You guessed too high!");
                //  guess = scan.nextInt();
  
            //  }
            //  else{
               //   if (guess &lt; answer &amp;&amp; guess != 0){ //If guess is lower than answer
                //      System.out.println ("You guessed too low!");
                //      guess = scan.nextInt();
                //  }
  
             //     else if (guess == answer){ //If guess equals answer
                   //   System.out.println ("You got it! Good guessing!");
           //       }
           //       else if (guess == 0){ //Game ends
                     // System.out.println ("You have ended your game. Goodbye.");
          //        }
          //            }
         //         }
       //   if (guess == answer){
            //  System.out.println ("You got it! Good guessing!");
       //   }
  
         // System.out.println ("Want to play again? (yes or no)?");
          //again = scan.next();
      //}
    //}
          }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>I'm thinking of a number between 1 and 100. Guess what it is: (or enter 0 to quit) 50
  You guessed too high!
  40
  You guessed too high!
  30
  You guessed too high!
  20
  You guessed too high!
  10
  You guessed too high!
  1
  You guessed too low!
  5
  You got it! Good guessing!
  </code></pre>
  
  <p>As you see from the comments in my code, I tried to duplicate the loop while also adding an if else statement and a question to ask the user if they want to play again. Is there an easier and working way to do re trigger the loop to make the game go on again?</p>
  
  <p>Thank you in advance</p>