Click here to Skip to main content
15,909,614 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I want to stop the execution of if-loop ,I have tried with 'return' statement but its exits from the function ,So how can I exit from the single if Statement.I have tried with following code...

C#
void A()
{

          if (CheckHorizontalSide(SourceMember))
            {
                
                if (lblHorizontalMember.Text == DestinationMember)
                {
                    
                    lsRelationPath.Add(lblHorizontalMember.Text);
                    lblRelationPath.Text = String.Join("-", lsRelationPath);
                    lblRelationPath.Visible = true;
                    return;
                }

                bool WhetherContains = lsRelationPath.Contains(SourceMember);
                if (WhetherContains)
                {
                    return;
                }

                lsMemberID1.Clear();
                lsRelationPath.Add(lblHorizontalMember.Text);
               

                Find_Route(lblHorizontalMember.Text, DestinationMember);
            }


	    if(CheckTop(SourceMember))
	    {
		//code here....
	    }
}
Posted
Comments
First of all if is not a loop, rather it is a conditional statement.

1 solution

Just need to re-organise the logic:
C#
if (CheckHorizontalSide(SourceMember))
  {
      bool WhetherContains = lsRelationPath.Contains(SourceMember);

      if (lblHorizontalMember.Text == DestinationMember)
      {

          lsRelationPath.Add(lblHorizontalMember.Text);
          lblRelationPath.Text = String.Join("-", lsRelationPath);
          lblRelationPath.Visible = true;
      }
      else if (!WhetherContains)
      {
           lsMemberID1.Clear();
           lsRelationPath.Add(lblHorizontalMember.Text);
          Find_Route(lblHorizontalMember.Text, DestinationMember);
      }

  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900