When would I use goto in C++?
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
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.
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]
[edited by - Drakkcon on April 12, 2004 2:01:42 PM]
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement