Goto Statement

In C language goto statement is also known as a Jump statement which is sometimes also referred as a Unconditional jump statement. Goto statement are also used to break the multiple loops which can’t be done by using a single break statement. It can be used to repeat some part of the code for a particular condition.

Syntax

label:
//some part of the code;
goto label;

let’s see the example of goto statement in C

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

Output

Enter the number of table5

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 =50

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews