You have non-looped, sequenced code, like below:
bool bFailed = true;
if(condition1_fails)
goto Exit;
...
if(condition2_fails)
goto Exit;
...
...
if(conditionN_fails)
goto Exit;
bFailed=false;
PerformActionOnAllSuccess();
Exit:
if(bFailed)
DoFailedCleanup();
else
DoNormalCleanup()
Here is the
goto
-less goto, that you can use:
bool bFailed=true;
do
{
if(condition1_fails)
break;
...
if(condition2_fails)
break;
...
...
if(conditionN_fails)
break;
bFailed = false;
PerformActionOnAllSuccess();
} while(false);
if(bFailed)
DoFailedCleanup();
else
DoNormalCleanup();
It runs a
do-while
loop, which would run only once. As soon as some failed-condition encounters, it exits (break) from loop.
Started programming with GwBasic back in 1996 (Those lovely days!). Found the hidden talent!
Touched COBOL and Quick Basic for a while.
Finally learned C and C++ entirely on my own, and fell in love with C++, still in love! Began with Turbo C 2.0/3.0, then to VC6 for 4 years! Finally on VC2008/2010.
I enjoy programming, mostly the system programming, but the UI is always on top of MFC! Quite experienced on other environments and platforms, but I prefer Visual C++. Zeal to learn, and to share!