Name

goto

Synopsis

The goto statement jumps to any point within a function. The destination of the jump is specified by the name of a label.

Syntax:

goto label_name;

A label is a name followed by a colon that appears before any statement.

Example:

for ( ... )         // Jump out of
    for ( ... )     // nested loops. 
       if ( error 
         goto  handle_error;
  ...
 handle_error:      // Error handling here
 ...

The only restriction is that the goto statement and the label must be contained in the same function. Nonetheless, the goto statement should never be used to jump into a block from outside it.

Get C Pocket Reference 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.