goto statement in C

goto statement in C

A goto statement in C is a jump statement that provides an unconditional jump from the ‘goto’ to a labeled statement in the same function.

The goto statement is used to repeat some part of the code for a particular condition. It is also used to break the multiple loops which cannot be done by using a single break statement. 

Syntax of goto statement in C

label:   
// code;   
goto label

Program of goto statement in C

#include <stdio.h>  
int main()   
{  
  int num,i=1;   
  printf("Enter the number:");   
  scanf("%d",&num);  
  table:   
  printf("%d x %d = %d\n",num,i,num*i);  
  i++;  
  if(i<=10)  
  goto table;    
}

Output

Enter the number:2
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

 

Read more, C-typedef

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *