What Is Goto in C Language

The goto statement is a jump statement which is sometimes also referred to as unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function.

What is the use of goto?

The goto statement can be used to alter the flow of control in a program. Although the goto statement can be used to create loops with finite repetition times, use of other loop structures such as for, while, and do while is recommended. The use of the goto statement requires a label to be defined in the program.

Why goto in C is bad?

Using a goto to jump out of a deeply-nested loop can often be cleaner than using a condition variable and checking it on every level. Using goto to implement subroutines is the main way it is abused. This creates so-called “spaghetti code” that is unnecessarily difficult to read and maintain.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest