title: Log out algorithm
body: <p>I am trying to create a simple logging in interface, where you can log in to change your information like email, username, password. The final piece of this puzzle for me is how can I send them back to the login screen after a lot of loops and steps:</p>
  <pre><code>package Exercises;
  
  import java.util.ArrayList;
  import java.util.Scanner;
  import java.util.regex.Pattern;
  
  
  import java.util.HashMap;
  
  public class Final {
      public static void main(String[] args) {
          ArrayList&lt;String&gt; email = new ArrayList&lt;String&gt;();
          HashMap&lt;String, String&gt; accounts = new HashMap&lt;String, String&gt;();
          try (Scanner scan = new Scanner(System.in)) {
              boolean n = true;
              while(n){
                  System.out.println(&quot;1 - Login&quot;);
                  System.out.println(&quot;2 - Register&quot;);
                  String number1 = scan.nextLine();
                  switch(number1){
                      case &quot;1&quot;:
                          boolean loginCheck = true;
                          while(loginCheck){
                              System.out.print(&quot;Enter username: &quot;);
                              String userIn = scan.nextLine();
                              if(accounts.containsKey(userIn)){
                                  System.out.print(&quot;Enter password: &quot;);
                                  String passIn = scan.nextLine();
                                  if (passIn == accounts.get(userIn)) {
                                      System.out.println(&quot;Welcome&quot; + userIn + &quot;, you can perform these actions: &quot;);
                                      System.out.println(&quot;1 - Change username&quot;);
                                      System.out.println(&quot;2 - Change email&quot;);
                                      System.out.println(&quot;3 - Change password&quot;);
                                      System.out.println(&quot;4 - Log out&quot;);
                                      System.out.println(&quot;0 - Exit&quot;);
                                      String number2 = scan.nextLine();
                                      switch (number2) {
                                          case &quot;0&quot;:
                                              System.exit(0);
                                              break;
                                          case &quot;1&quot;:
                                              System.out.print(&quot;Type the new username: &quot;);
                                              String newUser = scan.nextLine();
                                              accounts.remove(userIn);
                                              accounts.put(newUser, passIn);
                                              System.out.println(&quot;The username has been changed!&quot;);
                                              break;
                                          case &quot;3&quot;:
                                              System.out.print(&quot;Type the old email: &quot;);
                                              String oldMail = scan.nextLine();
                                              System.out.print(&quot;Type the new email: &quot;);
                                              String newMail = scan.nextLine();
                                              email.set(email.indexOf(oldMail), newMail);
                                              System.out.println(&quot;Email has been changed!&quot;);
                                              break;
                                          case &quot;4&quot;:
                                              
                                          default:
                                              break;
                                      }
                                  }
                                  else{
                                      System.out.println(&quot;Wrong password!&quot;);
                                      System.out.println(&quot;1 - Try again&quot;);
                                      System.out.println(&quot;2 - Forgot password&quot;);
                                      String fpassCheck = scan.nextLine();
                                      switch(fpassCheck){
                                          case &quot;1&quot;:
                                              break;
                                          case &quot;2&quot;:
                                              System.out.print(&quot;Type the email used to register: &quot;);
                                              String mailCheck = scan.nextLine();
                                              if (email.contains(mailCheck)) {
                                                  System.out.print(&quot;Type the new passwor: &quot;);
                                                  String newPass = scan.nextLine();
                                                  accounts.remove(userIn);
                                                  accounts.put(userIn, newPass);
                                                  System.out.println(&quot;Password has been changed.&quot;);
                                                  break;
                                              }
                                              else{
                                                  System.out.println(&quot;Account do not exist yet!&quot;);
                                                  break;
                                              }
                                          default:
                                              break;
                                      }
                                  }
                              }
                              else{
                                  System.out.println(&quot;Wrong username&quot;);
                              }
                          }                    
                      case &quot;2&quot;:
                          System.out.print(&quot;Enter email: &quot;);
                          String mailReg = scan.nextLine();
                          if(isValid(mailReg)){
                              if(email.contains(mailReg)){
                                  System.out.println(&quot;There is already an existing account using this email!&quot;);
                                  break;
                              }
                              else{
                                  email.add(mailReg);
                                  System.out.print(&quot;Create username: &quot;);
                                  String userReg = scan.nextLine();
                                  boolean passCheck = true;
                                  while (passCheck) {
                                      String passRegex = &quot;^(?=[A-Z])(?=.*[. , - _ ;]).{7,15}$&quot;;
                                      Pattern pat = Pattern.compile(passRegex);
                                      System.out.print(&quot;Tạo pasword: &quot;);
                                      String passReg = scan.nextLine();
                                      if (pat.matcher(passReg).matches()) {
                                          accounts.put(userReg, passReg);
                                          passCheck = false;
                                      }
                                      else{
                                          System.out.println(&quot;Password length must be between 7 and 15 characters, contains at least 1 uppercase, and 1 special character (. , - _ ;)&quot;);
                                      }
                                  }
                              }
                          }
                          else{
                              System.out.println(&quot;Incorrect Email, please try again.&quot;);
                      }
                  }
              }
          }
      }
  
      public static boolean isValid(String email)
      {
          String emailRegex = &quot;^(.+)@(.+)$&quot;;
                                
          Pattern pat = Pattern.compile(emailRegex);
          if (email == null)
              return false;
          return pat.matcher(email).matches();
      }
  }
  </code></pre>
  <p>After doing several actions, how can I make it so that it goes back to the login screen loop ? I assume that using multiple breaks is just really bad and might not even work properly.</p>