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

The goto-less goto!

0.00/5 (No votes)
1 Feb 2011CPOL 7K  
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:

C++
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)