Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

The goto-less goto!

4.88/5 (5 votes)
31 Jan 2011CPOL 9.3K  
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)