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

The goto-less goto!

4.50/5 (2 votes)
2 Apr 2011CPOL 10K  
Here goes my alternate.I am a C++ programmer. My goal is always to try to make code short and simple.bool bFailed=false;if (!bFailed) bFailed= condition1_fails;if (!bFailed) bFailed= condition2_fails;if (!bFailed) bFailed= condition3_fails;if (bFailed) DoFailedCleanup();else {...
Here goes my alternate.
I am a C++ programmer. My goal is always to try to make code short and simple.

bool bFailed=false;
if (!bFailed) bFailed= condition1_fails;
if (!bFailed) bFailed= condition2_fails;
if (!bFailed) bFailed= condition3_fails;

if (bFailed) DoFailedCleanup();
else { 
  PerformActionOnAllSuccess(); 
  DoNormalCleanup();
} 


Pros



  • Short and simple to read
  • You can set debug breakpoints in any condition to test return values
  • No functions / exceptions needed

License

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