title: Issues with proper looping in a do while loop - Java
body: <p>I seem to be having some issues with my program. I was advised to use a do while loop by my instructor to keep the program running. However, it errors out when I type in an invalid password and restarts. When I input a valid password it only prints "Valid Password" and does <em>not</em> loop. Where have I gone wrong?</p>
  
  <pre><code>import java.util.Scanner;
  
  public class CovenduniteProg5_FIX {
  
      public static void main(String[] args)      {
          boolean passwordValid = false;
  
          do  {
              boolean invalidLength = false;
              boolean containsRestrictedWord = false;
              boolean containsLowerCaseLetter = false;
              boolean containsUpperCaseLetter = false;
              boolean containsDigit = false;
              boolean containsSpecialChar = false;
  
              Scanner stdIn = new Scanner(System.in);
  
              System.out.println("Password Verifier"); 
              System.out.println("\nEnter a password that meets the following rules:\n" +
                  "\tIs at least 8 characters long\n" + 
                  "\tContains at least 1 lower letter character\n" +
                  "\tContains at least 1 upper letter character\n" +
                  "\tContains at least 1 numberic digit\n" +
                  "\tContains at least 1 special character from the set: !@#$%^&amp;*\n" +
                  "\tDoes not contain the word \"and\" or the word \"the\"\n");
              System.out.print("Enter your password: ");
              String password = stdIn.nextLine();
  
              for (int i = 0; i &lt; password.length(); i++) {
                  char ch = password.charAt(i);
  
                  if (Character.isUpperCase(ch) &amp;&amp; !containsUpperCaseLetter) {
                      containsUpperCaseLetter = true;
                  }
  
                  if (Character.isLowerCase(ch) &amp;&amp; !containsLowerCaseLetter) {
                      containsLowerCaseLetter = true;
                  }
  
                  if (Character.isDigit(ch) &amp;&amp; !containsDigit) {
                      containsDigit = true;
                  }
  
                  if ((ch == '!' || ch == '@' || ch == '#' || ch == '$' || ch == '%' || ch == '^' || ch == '&amp;' || ch == '*') &amp;&amp; !containsSpecialChar) {
                      containsSpecialChar = true;
                  }
              }
  
              if (password.length() &lt; 8 ) {
                  invalidLength = true;
              } 
  
              if (password.contains("and") || password.contains("the")) {
                  containsRestrictedWord = true;
              }
  
              if (invalidLength) {
                  System.out.println("Invalid: Invalid length");
              }
  
              if (containsRestrictedWord) {
                  System.out.println("Invalid: Contains either the word \"and\" or \"the\".");
              }
  
              if (!containsDigit) {
                  System.out.println("Invalid: Does not contain at least one digit.");
              }
  
              if (!containsLowerCaseLetter) {
                  System.out.println("Invalid: Does not contain at least one lowercase letter.");
              }
  
              if (!containsUpperCaseLetter) {
                  System.out.println("Invalid: Does not contain at least one uppercase letter.");
              }
  
              if(!containsSpecialChar) {
                  System.out.println("Invalid: Does not contain at least one special character.");
              }
  
              if (containsSpecialChar &amp;&amp; containsUpperCaseLetter &amp;&amp; containsLowerCaseLetter &amp;&amp; containsDigit &amp;&amp; !containsRestrictedWord &amp;&amp; !invalidLength)
                  passwordValid = true;
  
              if (passwordValid)
                  System.out.print("\nPassword is valid.");
  
          } while (!passwordValid);
  
          passwordValid = false;
  
          while(!passwordValid) {
              if (passwordValid)
                  System.out.print("\nPassword is valid.");
          }
      }
  }
  </code></pre>