c++goto

What is wrong with using goto?


Possible Duplicates:
Why is it bad to use goto?
GOTO still considered harmful?

I was ramdomming through xkcd and saw this one (if also read some negative texts about them some years ago):
your slow connection sucks, get a faster one to see this image
What is actually wrong with it? Why are goto's even possible in C++ then?

Why should I not use them?


Solution

  • Because they lead to spaghetti code.

    In the past, programming languages didn't have while loops, if statements, etc., and programmers used goto to make up the logic of their programs. It lead to an unmaintainable mess.

    That's why the CS gods created methods, conditionals and loops. Structured programming was a revolution at the time.

    gotos are appropriate in a few places, such as for jumping out of nested loops.