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

The goto-less goto!

0.00/5 (No votes)
26 Jan 2011CPOL 6.6K  
If the number of conditions is relatively small, the following code would made sense: bool bFailed = true; if (!condition1_fails) { if(!condition2_fails) { ... if(!conditionN_fails) { bFailed=false; ...
If the number of conditions is relatively small, the following code would made sense:

bool bFailed = true;
if (!condition1_fails)
{
   if(!condition2_fails)
   {
      ...
      if(!conditionN_fails)
      {
         bFailed=false;
         PerformActionOnAllSuccess();
         DoNormalCleanup();
      }
   }
}
if (bFailed)
{
   DoFailedCleanup();
}

License

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