Click here to Skip to main content
15,067,335 members
Articles / Programming Languages / C#
Posted 23 Apr 2010

Tagged as


9 bookmarked

The goto-less goto!

Rate me:
Please Sign up or sign in to vote.
3.34/5 (23 votes)
24 Jan 2011CPOL
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!

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
Memberi0021-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.