title: exit program do-while loop in java
body: <p>I am working on a java program. Right now everything is totally working, and all my functionality is there. However, the part I am stuck on is how to exit out of the program in a <code>do-while</code> loop. I must be getting the syntax wrong. </p>
  
  <p>Basically, I set a switch <code>done</code> which reacts to a user's input. Right now, it's working and loops through the program, but it does not exit if I say "no" to continuing. </p>
  
  <p>Here is the part of the code this is happening:</p>
  
  <pre><code>public void main() {
      String userInput;
      boolean done = true;
      Scanner keyboard = new Scanner(System.in);
      do {
          System.out.println("Welcome to Hangman!");
          System.out.println("Do you want to play?");
          userInput = keyboard.next();
          if (userInput.equals("Yes") || userInput.equals("yes") || userInput.equals("y") || userInput.equals("Y")) {
              done = false;
          } else if (userInput.equals("n") || userInput.equals("no") || userInput.equals("NO") || userInput.equals("No")) {
              done = true;
          }
          while (!done) {
            System.out.println(getDisguisedWord());   
            System.out.println("Guess a letter: ");
            String guess = keyboard.next();
            makeGuess(guess);
            if (gameOver()) {
                String ui;
                System.out.println("Do you want to play again?");
                ui = keyboard.next();
                if (ui.equals("Yes") || ui.equals("yes") || ui.equals("y") || ui.equals("Y")) {
                    done = false;
                } else {
                    done = true;
                }
            }
          }
      } while(done);
  }
  </code></pre>
  
  <p>any tips on how I could handle this better?</p>