This question already has an answer here:
- Examples of good gotos in C or C++ [closed] 16 answers
I know lots of questions about why not use goto
, why goto
is bad practice, why goto
was create by devil, why the fingers of those who type goto
should be ripped off, etc...
And in many answers to this questions , this question, and even at wikipedia it's possible to find reasons pro / against goto
.
Even Stackoverflow has a goto
tag :)
But, obviously, goto
is accepted as a valid command, otherwise your compiler / interpreter wouldn't know what to do with it. Even in C / C++ it's possible to use goto
, and that language even has a formal, ISO specification.
So, probably, there should be some case where only by using goto
it's possible to accomplish some task. Then, why and when should a goto
be used in C / C++ ?
Edit:
Just to make sure:
1 - this question doesn't require debate. It should be answerable: giving one or more cases where goto
is the only solution, or stating no, it's always possible to avoid a goto
. Of course, I'm not the only who can decide whether it should be closed or not, but I don't think that "too broad, asks for debate, etc" are reasons to close it.
2 - There might be some cases where goto
make the code cleaner, faster, etc. I don't want those. I want to know if there exists one case where goto
is the only solution (no, it's not a dup of that "give good examples of goto" question)
3 - I'll accept any downvote, with a smile on my face, if the downvote is justified. But I'm pretty sure that this question has an answer and has done previous research about the subject. Downvoting simple because those 4-letters taboo word that starts with a "G" was used... sorry...