title: Creating java code to prompt user for password and allow only 3 attempts then quit the programme
body: <p>I have been experimenting with trying to get the code below running WITHOUT using a break statement (but i can't figure it out)</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class Password
  {
      public static void main (String [] args)
      {
          final String PASSWORD = "Test";
  
          for (int passAttempts = 0; passAttempts &lt; 3; passAttempts++) 
          {
              System.out.print("\nEnter Your Password: ");
              Scanner input = new Scanner(System.in);
              String inputPass = input.nextLine();
  
              if (!(inputPass.equals(PASSWORD))) 
              {
                  System.out.println("\nWrong Password Try Again");
              } 
              else 
              {
                  System.out.println("\nWelcome!");
                  break;
              }
          }
      }
  }
  </code></pre>
  
  <p>This is my alternative attempt of trying to use a switch statement to "catch" each iteration of the loop and perform an action, but I'm  not sure why its endless loop:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class Password2
  {
      public static void main (String [] args)
      {
          final String PASSWORD = "Test";
  
          System.out.print("\nEnter Your Password: ");
          Scanner input = new Scanner(System.in);
          String inputPass = input.nextLine();
  
          do
          {
              for(int passAttempts = 0; passAttempts &lt; 3; passAttempts++)
              {
                  switch(passAttempts)
                  {
                      case 0:
                          System.out.println("\nWrong password try again\t2 attempts remaining");
                          break;
                      case 1:
                          System.out.println("\nWrong password try again\t1 attempts remaining");
                          break;
                      case 2:
                          System.out.println("\nWrong password try again\t0 attempts remaining");
                          break;
                      default:
                          System.out.println("\nContact Help desk");
                          break;
                  }  
              }    
          }
          while(!(inputPass.equals(PASSWORD)));
      }
  }
  </code></pre>
  
  <p>Where am I going wrong?</p>