

goto                        C Keyword                        goto




Unconditionally jump within a function


A goto command  jumps to the area of the  program introduced by a
label.  A program can goto only within a function; to jump across
function  boundaries,  you  must  use  the functions  setjmp  and
longjmp.

In the context of C programming,  the most common use for goto is
to exit from a control block or go to the top of a control block.
It  is  used  most often  to  write  ``ripcord'' routines,  i.e.,
routines that are executed  when an major error occurs too deeply
within  a function  for the  program  to disentangle  itself cor-
rectly.  Note that in most instances, goto is a bad solution to a
problem that can be better solved by structured programming.

***** Example *****

The following example demonstrates how to use goto.


#include <stdio.h>



main()
{
        char line[80];



getline:
        printf("Enter line: ");
        fflush(stdout);
        gets(line);



/* a series of tests often is best done with goto's */
        if (*line == 'x') {
                printf("Bad line\n");
                goto getline;
        } else if (*line == 'y') {
                printf("Try again\n");
                goto getline;
        } else if (*line == 'q')
                goto goodbye;
        else
                goto getline;







COHERENT Lexicon                                           Page 1




goto                        C Keyword                        goto



goodbye:
        printf("Goodbye.\n");
        exit(0);
}


***** See Also *****

C keywords

***** Notes *****

_T_h_e _C  _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e describes  goto as ``infinitely-abus-
able'': caveat utilitor.











































COHERENT Lexicon                                           Page 2


