Click here to Skip to main content
15,909,566 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to go outseide if statemnet but only with help of if else statement hoe it can be possible
Posted
Comments
Vani Kulkarni 8-Aug-12 2:32am    
This is not well composed question. Please use Improve question and try to explain what exactly you are looking for.
Santhosh Kumar Jayaraman 8-Aug-12 2:52am    
Please mention what you want clearly, so that we can help you

AFAIK you can't 'break out' of an if statement.

If you are attempting this, your logic is wrong and you are approaching it from the wrong angle.

In VB.net:
VB
if i > 0 then
      'Write your code here..
   end if

In C#:
C#
if (i > 0)
   {
     //Write your code here!
   }


Post your code snippets of what you're trying and where exactly you want to 'break'. An example of what you are trying to achieve would help clarify, but I suspect you are structuring it incorrectly.
 
Share this answer
 
You can use return; keyword to break if..else.. statement.
Refer the links for more details:
MSDN : return[^]

--Amit
 
Share this answer
 
v2
Comments
[no name] 8-Aug-12 2:53am    
thnx sir
_Amy 8-Aug-12 2:56am    
Welcome deepshikha. :)
There is no "break" statement for if...else constructs in the way there is for loops and switch statements.
You probably need to look at your logic, and change the order in which you are doing things, or refactor your code to use methods instead - you can exit a method with a return statement at any time.

There are two other alternatives:
1) If this is an error condition, then throwing an exception is a good idea.
2) There is a goto statement, but you really shouldn't need it - I can't remember the last time I really needed one, but it is probably ten years ago or more! Avoid unless there is no other alternative, comment profusely, and expect to get abuse anyway for using it in the first place. Goto is the first thing to be spotted at a code review, so there had better be a very, very good justification.
 
Share this answer
 
Revising the logic of your program would probably be a better option.
 
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