Click here to Skip to main content
12,508,470 members (53,966 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.4K views
2 bookmarked
Posted

The goto-less goto!

, 1 Feb 2011 CPOL
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

You may also be interested in...

Pro
Pro

Comments and Discussions

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

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160927.1 | Last Updated 1 Feb 2011
Article Copyright 2011 by abridges
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid