title: How to break a do while loop?
body: <p>I am new to coding and have been trying to make a login using textfiles (i know i know its not secure its for practice with text files)</p>
  
  <pre><code>namespace text_file_login
  {
      public partial class Login : Form
      {
          public Login()
          {
              InitializeComponent();
          }
  
          private void btn_register_Click(object sender, EventArgs e)
          {
              StreamWriter user_reg =
                  new StreamWriter(@"E:\SSD\Controled Assesment\text file login\text file login\username.txt");
              StreamWriter pass_reg =
                  new StreamWriter(@"E:\SSD\Controled Assesment\text file login\text file login\password.txt");
  
              user_reg.WriteLine(txt_user.Text);
              user_reg.Close();
              pass_reg.WriteLine(txt_pass.Text);
              pass_reg.Close();
  
              MessageBox.Show("Register was sucessful");
          }
  
          private void btn_login_Click(object sender, EventArgs e)
          {
              string user = "";
              string pass = "";
              int user_line_number = 0;
              int pass_line_number = 0;
              StreamReader user_login =
                  new StreamReader(@"E:\SSD\Controled Assesment\text file login\text file login\username.txt");
              StreamReader pass_login =
                  new StreamReader(@"E:\SSD\Controled Assesment\text file login\text file login\password.txt");
              do
              {
                  user = user_login.ReadLine();
                  user_line_number++;
                  if (user == txt_user.Text)
                  {
                      do
                      {
                          pass = pass_login.ReadLine();
                          pass_line_number++;
                          if ((pass == txt_pass.Text) &amp;&amp; (user_line_number == pass_line_number))
                          {
                              MessageBox.Show("Login was succesful");
                              //this.Close();
                          }
                          else
                          {
                              if ((user_line_number &gt; pass_line_number) || (user_line_number &lt; pass_line_number))
                              {
                                  MessageBox.Show("Wrong Password");
                              }
                          }
                      } while (pass_login.Peek() != -1);
                  }
              } while (user_login.Peek() != -1);
          }
      }
  }
  </code></pre>
  
  <p>The login works and the register works. However if the username or password is wrong im pretty sure this loops forever. How do i end the loops so that if the username or password is wrong i can show a messagebox?
  im not too fused about multiple usernames however if you could is there anyway to fix this?</p>
  
  <p>Sorry if this is poorly written. I am a beginner  </p>