Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

The goto-less goto!

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
26 Jan 2011CPOL 6.3K   2   1
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)


Written By
Software Developer (Senior)
Canada Canada
Programmer at Maid LABS from 2003 (www.maidlabs.com)

Programmer-Analyst at Viasat Geo Technoligies from 1995 to 2002 (www.viasat-geo.com).

I have studied at École Polytechnique de Montréal in computer engineering.

Comments and Discussions

 
GeneralWhile valid and better than the goto, this type of coding ca... Pin
fjdiewornncalwe26-Jan-11 14:56
professionalfjdiewornncalwe26-Jan-11 14:56 

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.