Click here to Skip to main content
13,899,955 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 23 Apr 2010
Licenced CPOL

The goto-less goto!

, 24 Jan 2011
Rate this:
Please Sign up or sign in to vote.
The goto-less goto!
You have non-looped, sequenced code, like below:

  bool bFailed = true;
     goto Exit;
     goto Exit;
     goto Exit;



Here is the goto-less goto, that you can use:
bool bFailed=true;

   bFailed = false;

 } while(false); // Ignore or disable warning at function-level


It runs a do-while loop, which would run only once. As soon as some failed-condition encounters, it exits (break) from loop.


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


About the Author

Ajay Vijayvargiya
Software Developer (Senior)
India India
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!

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
Manikandan106-Jun-14 20:52
professionalManikandan106-Jun-14 20:52 
GeneralMy vote of 1 Pin
Krzysztof Kalinowski12-Mar-13 21:25
memberKrzysztof Kalinowski12-Mar-13 21:25 
GeneralMy vote of 1 Pin
i0021-Oct-12 16:01
member i0021-Oct-12 16:01 
GeneralReason for my vote of 2 No reason at all to use loop stateme... Pin
Albert Holguin14-Oct-11 5:01
professionalAlbert Holguin14-Oct-11 5:01 
GeneralReason for my vote of 5 This is a very good alternate to usi... Pin
EFEaglehouse5-Apr-11 4:06
memberEFEaglehouse5-Apr-11 4:06 
GeneralReason for my vote of 1 Misused gotos has been replaced by m... Pin
Mass Nerder8-Feb-11 3:18
memberMass Nerder8-Feb-11 3:18 
GeneralReason for my vote of 5 I've looked at the many alternates, ... Pin
Carroll Arbogast7-Feb-11 13:01
memberCarroll Arbogast7-Feb-11 13:01 
GeneralReason for my vote of 3 Not very efficient, too many breaks. Pin
BillW332-Feb-11 8:18
professionalBillW332-Feb-11 8:18 
GeneralReason for my vote of 1 IF you find yourself in this positio... Pin
Kirk Wood31-Jan-11 15:10
memberKirk Wood31-Jan-11 15:10 
GeneralRe: Now what Polymorphism has to do with this? Pin
Ajay Vijayvargiya2-Feb-11 15:57
memberAjay Vijayvargiya2-Feb-11 15:57 
GeneralGoto are not always bad... There are very specific cases whe... Pin
Valery Possoz31-Jan-11 12:46
professionalValery Possoz31-Jan-11 12:46 
GeneralRe: You are absolutely correct. An inspection of Dijkstra's pap... Pin
Ravi Bhavnani6-Apr-11 8:25
professionalRavi Bhavnani6-Apr-11 8:25 
GeneralI don't use gotos either. My point was "how to avoid goto, i... Pin
Ajay Vijayvargiya24-Jan-11 16:15
memberAjay Vijayvargiya24-Jan-11 16:15 
GeneralRe: If you feel you need to use goto, I'd say you need to re-eva... Pin
fjdiewornncalwe26-Jan-11 14:54
professionalfjdiewornncalwe26-Jan-11 14:54 
GeneralWhy not use if - else if - else if ...? You won't need to br... Pin
Indivara24-Jan-11 13:24
professionalIndivara24-Jan-11 13:24 
GeneralGoto / multiple returns rules and alternatives Pin
Philippe Mori7-Apr-11 2:53
memberPhilippe Mori7-Apr-11 2:53 
General[My vote of 1] Pointless Pin
balab31-Jan-11 8:58
memberbalab31-Jan-11 8:58 
GeneralRe: [My vote of 1] Pointless Pin
wim ton31-Jan-11 21:30
memberwim ton31-Jan-11 21:30 
GeneralRe: [My vote of 1] Pointless Pin
mier7-Mar-11 22:43
membermier7-Mar-11 22:43 
GeneralMy vote of 1 Pin
SledgeHammer0124-Apr-10 8:23
memberSledgeHammer0124-Apr-10 8:23 
GeneralRe: My vote of 1 Pin
Ajay Vijayvargiya25-Apr-10 9:37
memberAjay Vijayvargiya25-Apr-10 9:37 
GeneralRe: My vote of 1 [modified] Pin
SledgeHammer0125-Apr-10 10:13
memberSledgeHammer0125-Apr-10 10:13 
GeneralRe: My vote of 1 Pin
supercat926-Apr-10 6:31
membersupercat926-Apr-10 6:31 
GeneralRe: My vote of 1 Pin
Ajay Vijayvargiya26-Apr-10 18:37
memberAjay Vijayvargiya26-Apr-10 18:37 
GeneralFine but..... Pin
Abhinav S23-Apr-10 22:27
memberAbhinav S23-Apr-10 22:27 

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 | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 24 Jan 2011
Article Copyright 2010 by Ajay Vijayvargiya
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid