Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

The goto-less goto!

By , 26 Jan 2011
Rate this:
Please Sign up or sign in to vote.
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)

About the Author

Philippe Mori
Web Developer
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... PinmemberMarcus Kramer26-Jan-11 14:56 

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 | Mobile
Web01 | 2.8.140415.2 | Last Updated 26 Jan 2011
Article Copyright 2011 by Philippe Mori
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid