title: checking a password in a loop
body: <p>I am writing a simple program where a user enters a password to use a directory system. </p>
  
  <p>If the user choses not to enter any details I want to log them out and then give them the option to log back in again. I have tried doing this with a loop (see code below) but when I reset the passQ vairable to 0 I was expecting it to log the user out and return to the opening statement in the loop... but that doesnt happen. </p>
  
  <p>Can anyone point me in the right direction. </p>
  
  <p>I tried adding break; (commented out bellow) but this just ended the program. </p>
  
  <p>p.s. I know this way of managing the password isn't really secure, I was just having a play as I may want to use loops like this for other things in the future. </p>
  
  <pre><code>package directory;
  
  import java.util.ArrayList;
  import java.util.Scanner;
  
  public class Directory {
  
  /**
   * @param args the command line arguments
   */
  //-------------//
  //Main Meathod //
  //-------------//
  public static void main (String[] args)
  {
      //------------------//
      // Define Variables //
      //------------------//
      String question = "Y";
      String passQ    = "0";
      String password = "password";
  
      Scanner passCheck = new Scanner(System.in);
      System.out.println("Welcome to Chris Headleands Tel Directory, Enter Password to access sytems"); //1 and 0 used for yes and no
      question = passCheck.nextLine(); // Next line used to decide if the user wants to enter a persons details
      while (passQ != password)
      {
          if (question.equalsIgnoreCase("password")) //Do they want to ender a person? 1 == yes
          {
  
              //Create a new array list for the people created
              ArrayList&lt;TelEntry&gt; directory = new ArrayList&lt;TelEntry&gt;();
  
              //Check if the user wants to create a new person
              Scanner checker = new Scanner(System.in);
              System.out.println("would you like to add a directory entry(1 = Yes / 0 = NO!)"); //1 and 0 used for yes and no
              question = checker.nextLine(); // Next line used to decide if the user wants to enter a persons details
  
              if (question.equalsIgnoreCase("y")) //Do they want to ender a person? 1 == yes
              {
                  while (question.equalsIgnoreCase("y")) // Add a loop so multiple people can be added
                  {
  
                      String name; // First name
                      String telNo; // Last name
  
                      // Create scanner for entering details
                      Scanner keybd = new Scanner(System.in);
  
                      //----------------------------------//
                      //User to enter details via keyboard//
                      //----------------------------------//
  
                      // Ask user to set first name
                      System.out.println("Enter their first name");
                      name = keybd.nextLine();
  
                      // Ask user to set last name
                      System.out.println("Enter their last name");
                      telNo = keybd.nextLine();
  
                      // -------------------------------------//
                      //Add the new person to personlist array//
                      //--------------------------------------//
                      directory.add(new TelEntry(name, telNo));
  
                      //-----------------------------------------------------------------------------//
                      // Check to see if the user wants to add another person, if Y then re-run loop //
                      //-----------------------------------------------------------------------------//
                      Scanner newChecker = new Scanner(System.in);
                      System.out.print("would you like to enter another person? (1 = Yes / 0 = NO!)");
                      question = newChecker.nextLine();  
  
                  }
  
  
              }
  
              //--------------------------------------------------------------//
              // User doesnt want to add any people to the persontest program //
              //--------------------------------------------------------------//
              if (question.equalsIgnoreCase("testmode"))
              {
                  System.out.println("you are now in test mode")
              }
              else
              { // Provide the user with a witty retort                     
                  System.out.println("if your not going to use me for what I was designed to do, bugger off and bother someone else!");
                  System.out.println("Logging out");
                  passQ = "0"; // Reset password loop
                  // break;
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>