title: Using IF condition inside a while loop in C#. False value still looping
body: <p>I don't know why my else value inside my while loop is still looping, whether the result is login or invalid. The alertdialog is always pop-up.</p>
  
  <p>These are my codes.</p>
  
  <pre><code>MySqlConnection conn = new MySqlConnection();    
  string query = "server=sample.com;port=3306;database=sample;user id=sample;password=sample";
  conn.ConnectionString = query;
  
  MySqlCommand cmd = new MySqlCommand("select * from wp_users", conn);
  try
  {
      conn.Open();
  
  
      MySqlDataReader myReader = cmd.ExecuteReader();
  
      string user1 = "";
      string pass1 = "";
      //bool stopLoop = false; // stop looping for false value;
      while (myReader.Read())
      {
  
          user1 = myReader[1].ToString(); //datacolumn -&gt; user_login
          pass1 = myReader[2].ToString(); //datacolumn -&gt; user_pass
  
          if ((user1 == txtUsername.Text) &amp;&amp; (pass1 == txtPassword.Text))
          {
  
              Intent myIntent;
              myIntent = new Intent(Activity, typeof(index));
  
              string a = user1;
  
              myIntent.PutExtra("myItem", a);
              StartActivity(myIntent);
          }
          else
          {
              Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(Activity);
              alert.SetMessage("Invalid username or password");
              alert.SetPositiveButton("Ok", (senderAlert, args) =&gt;
              {
                  alert.Dispose();
              });
              alert.Show();
          }
      }
      myReader.Close();
  }
  catch (MySqlException ex)
  {
      Android.Support.V7.App.AlertDialog.Builder except = new Android.Support.V7.App.AlertDialog.Builder(Activity);
      except.SetTitle("Please report this to our website(error server timeout)");
      except.SetMessage(ex.ToString());
      except.SetPositiveButton("Ok", (senderAlert, args) =&gt;
      {
          except.Dispose();
      });
      except.Show();
  }
  finally
  {
      conn.Close();
  }
  </code></pre>