title: Stop execution of a method as soon as one IF condition is met in c#
body: <p>I got a couple of if statements. What I want is, as soon as one condition is met, I should get out of the method. I will be using this if statements on filtering data for a datagridview or report. With my code below, it doesn't do this. It seems to go through all conditions. As soon as it finds a condition that meets it, the program executes it and proceeds to another if statement and if it sees that it meets the condition also, it too gets executed.
  I think this is pretty basic for you. I don't remember or know how I should do this.</p>
  
  <pre><code>private void btnRoute_Click(object sender, EventArgs e)
      {
          if (cbWithRoute.Checked)
          {
              // StartSearch(txtRoute.SelectedValue.ToString());
              MessageBox.Show(@"route");
          }
          if (cbWithRoute.Checked &amp;&amp; cbWithWholeSeller.Checked)
          {
              //StartSearch(txtRoute.SelectedValue.ToString(), txtWholeSeller.SelectedValue.ToString());
              MessageBox.Show(@"route wholeseller");
          }
          if (cbWithRoute.Checked &amp;&amp; cbWithCustomer.Checked)
          {
              MessageBox.Show(@"route customer");
          } 
          if (cbWithRoute.Checked &amp;&amp; cbWithWholeSeller.Checked &amp;&amp; cbWithDate.Checked)
          {
              //StartSearch(txtRoute.SelectedValue.ToString(),
              //    txtWholeSeller.SelectedValue.ToString(), Convert.ToDateTime(txtFromDate.Text).ToShortDateString(),
              //    Convert.ToDateTime(txtToDate.Text).ToShortDateString());
              MessageBox.Show(@"route wholseller date");
          }
          if (cbWithRoute.Checked &amp;&amp; cbWithCustomer.Checked &amp;&amp; cbWithDate.Checked)
          {
              MessageBox.Show(@"route date customer");
          }
          if (cbWithRoute.Checked &amp;&amp; cbWithWholeSeller.Checked &amp;&amp; cbWithDate.Checked &amp;&amp; cbWithCustomer.Checked)
          {
              //StartSearch(txtRoute.SelectedValue.ToString(),
              //    txtWholeSeller.SelectedValue.ToString(), Convert.ToDateTime(txtFromDate.Text).ToShortDateString(),
              //    Convert.ToDateTime(txtToDate.Text).ToShortDateString(), txtCustomer.SelectedValue.ToString());
              MessageBox.Show(@"route wholeseller date customer");
          }
          //else
          //{
          //    MessageBox.Show(@"Check criteria to search.");
          //}
  
      }
  </code></pre>
  
  <p>I commented the true code and replaced it with message boxes to show me what checkboxes are checked. Thank you.</p>