title: Can if statements be nested in a while loop?
body: <p>I've been working with code that uses a do-while loop, and I wanted to add an if else statement into that loop. The do-while loop checks to see what text the user enters and will finish if the word 'exit' is entered.</p>
  
  <pre><code>public static void main(String[] args) {
  
      String endProgram = "exit";
      String userInput;
      java.util.Scanner input = new java.util.Scanner(System.in);
  
      do {
  
          userInput = input.nextLine();
          if ( !userInput.equalsIgnoreCase(endProgram) ) {
              System.out.printf("You entered the following: %s", userInput);
          } else
  
      } while ( !userInput.equalsIgnoreCase(endProgram) );
  
  }
  </code></pre>
  
  <p>When I try to compile this code, I get an error from the command prompt saying:</p>
  
  <pre><code>SentinelExample.java:20: error: illegal start of expression
              } while ( !userInput.equalsIgnoreCase(endProgram) );
              ^
  SentinelExample.java:22: error: while expected
        }
         ^
  SentinelExample.java:24: error: reached end of file while parsing
  }
   ^
  </code></pre>
  
  <p>When I remove the if else statement in the loop, the program compiles fine. Is there something wrong with the syntax in my program? Or is it not possible to put an if else statement in a while loop?</p>