65.9K
CodeProject is changing. Read more.
Home

The goto-less goto!

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jan 25, 2011

CPOL
viewsIcon

6561

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();
   }