Click here to Skip to main content
11,703,632 members (69,668 online)
Click here to Skip to main content

Tagged as

The goto-less goto!

, 31 Jan 2011 CPOL 2.5K 3
Rate this:
Please Sign up or sign in to vote.
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 Currently looking for work
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
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    Rant Rant    Admin Admin   

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 31 Jan 2011
Article Copyright 2011 by jsc42
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid