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

Tagged as

The goto-less goto!

, 1 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Alternate 8, why not just do this:bool bFailed = true;// In case of an exception.try{ // while bFailed while (bFailed) { // do something here. if (condition1) { // exit the loop (goto) bFalse = false; ...
Alternate 8, why not just do this:
 
bool bFailed = true;
// In case of an exception.
try
{
    // while bFailed
    while (bFailed)
    {
        // do something here.
        if (condition1)
        {
            // exit the loop (goto)
            bFalse = false;
            break;
        }
        // do something here.
        // ....
        // In case you want to goto to the top instead of exit.
        if (condition2)
        {
            // jump to top of the loop. (goto)
            continue;
        }
        // Success.
        bFailed = false;
 
    }
}
catch (...)
{
    // this assumes you want to catch all.
}
 
if (bFailed)
{
    // do your error cleanup here.
}
// do your unconditional cleanup here.

License

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

Share

About the Author

abridges
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralI was only looking at alternate 8 which uses a empty for loo... Pinmemberabridges7-Feb-11 3:57 
GeneralI think that you have some problems with you code. First, i... Pinmembersergio_ykz7-Feb-11 3:49 

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
Web02 | 2.8.140827.1 | Last Updated 1 Feb 2011
Article Copyright 2011 by abridges
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid