When would I use goto in C++?

Started by
7 comments, last by Drakkcon 20 years ago
Is there ANY situation in which it would be acceptable coding style to use the goto command? The true general first seeks victory, then seeks battle - Sun Tzu
Advertisement
Probably not. Functions can serve the same purpose as a goto. You never know, just keep coding and maybe you will find an exception.
Opinions are divided. Some people think it''s acceptable to use them to break out of nested loops. Some people do not. Other than that, I am not aware of any general situation where they are considered anything but Harmful.
Of course. Like any other tool, goto must be used with responsibility.
So like what Miserable said, it would be acceptable to use goto in the place of break if I wanted to? Come to think of it I can't see a single situation where I'd use that...

[edited by - Drakkcon on April 12, 2004 2:01:42 PM]
I used goto recently in a really, really small application. I felt kinda bad.
2 + 2 = 5 for extremely large values of 2
quote:Original post by Drakkcon
So like what Miserable said, it would be acceptable to use goto in the place of break if I wanted to? Come to think of it I can''t see a single situation where I''d use that...

A break would only break out of the immediately enclosing loop. If you wanted to break out of two or more nested loops, you''d need a goto.

Java has labeled breaks just for this purpose.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
all right, a practical application. I''ll keep that in mind.
Read.
Read.
Read.

But make sure you read this one, which is the most concise and informative on the proper use and behavior of goto.

Thread closed. No need to rehash those multi-page discussions.

This topic is closed to new replies.

Advertisement