Skip to main content

Use this tag for questions concerning teaching the goto statement and its equivalents.

The goto statement is used to transfer control directly from one place in a program to another, often to a label. Its use was effectively obsoleted when structured programming. was created around 1965 or so. It is needed in assembly language, which has few if any other ways to transfer control. It is also included in many more modern languages. Even Java has some control transfer statements that are roughly equivalent to a goto, though with some restrictions (break, continue).

While goto statements can be used to implement higher level program logic structures such as if-then and while-do, they can also be used to create unreadable and unmaintainable code, often called spaghetti code_ for the way the transfer seems to wander around through the program.