C goto

The goto statement is used to jump from one line to another line in the program. Using goto statement we can jump from top to bottom or bottom to top. To jump from one line to another line, the goto statement requires a label. Label is a name given to the instruction or line in the program. When we use a goto statement in the program, the execution control directly jumps to the line with the specified label.

Syntax 

label

//some part of the code;

goto label;


Example

To print multiplication table of any number

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

Output

 





No comments:

Post a Comment