Posted in All Posts

Why is goto discouraged?

Before blaming and abusing goto, we should know what is goto.

What is goto?

goto is an unconditional jump of control from a part of the program to another part of the program.

goto is a natural mechanism of C like all other mechanisms like for loop, while loop, etc.

It is useful in smaller programs (I mean really small) but as it is used in larger programs, the flow of the program becomes harder to trace and makes the program unreadable.

Suppose, you make a huge program of a bank database and use goto excessively, then a person has to search the particular label for each goto to understand the code and logic of the program.
The person will curse you for that!

Disadvantages of using goto:
1. Becomes difficult to trace the control flow of the program.
2. Makes the program complex.
3. Reduces readability of the program.
4. Any program can be written without a goto (A nicely structured program!).
5. Alters the sequential flow of program, which is a characteristic of C.

goto meme
A GOTO is a weak way out when you have weak design. Velociraptors prey on the weak.

The above image illustrates what I want to say beautifully!

The goto statement is useful, no doubt but I’d say avoiding goto is the best habit, because as you make complex programs, that habit will save you!

If you are still not convinced (Oh God, Why?), you should see this discussion.

We hope that you found this article to be helpful.
Please share your thoughts in the Comments Section.

If you liked this article, then please like our Facebook page.

Suggested Reading

Comment your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.