The goto Statement

The goto statement, bulwark of the older versions of BASIC and FORTRAN, is available in C. However, C, unlike those two languages, can get along quite well without it. Kernighan and Ritchie refer to the goto statement as “infinitely abusable” and suggest that it “be used sparingly, if at all.” First, we will show you how to use goto. Then, we will show why you usually don't need to.

The goto statement has two parts—the goto and a label name. The label is named following the same convention used in naming a variable, as in this example:

goto part2;

For the preceding statement to work, the function must contain another statement bearing the part2 label. This is done by beginning a statement with the label name followed by a ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.