C Programming Tutorial
Computer Tutorial

The goto statement



The goto statement

The goto statement is used to move the program control at a particular position. In a difficult programming situation it seems so easy to use a goto to take the control where we want.
The goto statement requires a label for operation. (A label is a valid identifier followed by a colon.) Furthermore, the label must be in the same function as the goto that uses it— you cannot jump between functions.

The general form of the goto statement is


goto label ;
.
.
.
label :

C Program to show the use of goto operator :

\* C Program to show the use of goto operator *\
# include < stdio.h >
int   main( )
{
int   goals  ;
printf(" Enter the number of goals scored against India : ") ;
scanf("%d ", & goals) ;
if ( goals <= 5 )
goto sos  ;
else
{

printf("\n About time soccer players learnt C\n") ;
printf("\n and said goodbye! adieu! to soccer\n") ;
exit( ) ;

}
sos :
printf("\n To err is human! \n") ;
return ( 0 );

}