Click here to Skip to main content
13,201,050 members (59,428 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3K views
2 bookmarked
Posted 1 Feb 2011

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:

<br />
<pre lang="c++"><br />
bool bFailed = true;<br />
// In case of an exception.<br />
try<br />
{<br />
    // while bFailed<br />
    while (bFailed)<br />
    {<br />
        // do something here.<br />
        if (condition1)<br />
        {<br />
            // exit the loop (goto)<br />
            bFalse = false;<br />
            break;<br />
        }<br />
        // do something here.<br />
        // ....<br />
        // In case you want to goto to the top instead of exit.<br />
        if (condition2)<br />
        {<br />
            // jump to top of the loop. (goto)<br />
            continue;<br />
        }<br />
        // Success.<br />
        bFailed = false;<br />
<br />
    }<br />
}<br />
catch (...)<br />
{<br />
    // this assumes you want to catch all.<br />
}<br />
<br />
if (bFailed)<br />
{<br />
    // do your error cleanup here.<br />
}<br />
// do your unconditional cleanup here.<br />
<br />
</pre><br />

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
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 1 Feb 2011
Article Copyright 2011 by abridges
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid