Click here to Skip to main content
14,979,837 members
Articles / Programming Languages / C#
Alternative
Tip/Trick
Posted 31 Jan 2011

Tagged as

Stats

7.4K views
3 bookmarked

The goto-less goto!

Rate me:
Please Sign up or sign in to vote.
4.88/5 (5 votes)
31 Jan 2011CPOL
It is much easier (and cleaner) to test for success than to test for failure.Viz:if ( condition1 // Note: Test for success, not for fail && condition2 // Will be short-circuited if condition1 fails && condition3 // Will be short-circuited if condition1 or condition 2...
It is much easier (and cleaner) to test for success than to test for failure.
Viz:


if (  condition1   // Note: Test for success, not for fail
   && condition2   // Will be short-circuited if condition1 fails
   && condition3   // Will be short-circuited if condition1 or condition 2 fails
   ...
   && conditionn
   )
{
   PerformActionOnAllSuccesses(); 
   DoNormalCleanUp(); 
}  // if
else
   DoFailedCleanUp();

License

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

Share

About the Author

jsc42
Software Developer DDC OS
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralFor me is one of the simplests aproaches. 5 for you. Pin
Jose David Pujo31-Mar-11 21:34
MemberJose David Pujo31-Mar-11 21:34 
GeneralI wonder why there haven't been any prior positive comments ... Pin
George Henry 19548-Mar-11 3:41
MemberGeorge Henry 19548-Mar-11 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.