goto Statement in C

This “goto Statement in C language” providing syntax, examples about how to used goto statement in C Logical programming.


 

goto :

  • It is a branching statement.
  • It is used to send the control from one location to another location within the Program.
  • Switching control by defining labels.
  • Label creation rules as same as variable creation rules.

 

#include<stdio.h>
main()
{
int i=1;

top :
printf(“i : %d\n”,i);
i++;

if(i<=10)
{
goto top;
}
}

 

Note : It is allowed to define more than one label in C program.
#include<stdio.h>
main()
{
top :
printf(“top\t”);
//goto bottom;

printf(“center\t”);

bottom :
printf(“bottom\n”);
goto top;
}
‚Äč

Note : We can use goto statement to come out of infinite loop also.
#include<stdio.h>
main()
{

while(1)
{
printf(“while\n”);
goto bottom;
}

bottom :
printf(“bottom\n”);
}

Share this