C Goto Statement

The goto statement is a jump statement which jumps from one point to another point within a function. The goto statement is marked by label statement.

C Goto Statement

C Goto Statement

     

This section explains you the concept of 'goto' statement in C. 

The goto statement is a jump statement which jumps from one point to another point within a function. The goto statement is marked by label statement. Label statement can be used anywhere in the function above or below the goto statement. You can see in the given example, we want to display the numbers from 0 to 9. For this, we have defined the label statement loop above the goto statement. The given program declares a variable n initialized to 0. The n++ increments the value of n till the loop reaches 10. Then on declaring the goto statement, it will jumps to the label statement and prints the value of n.

Here is the code:

GOTOST.C

#include <stdio.h>
#include <conio.h>
int main() {
  int n = 0;
  loop: ;
 
  printf("\n%d", n);
  n++;
  if (n<10) {
  goto loop;
  }
  getch();
  return 0;
}

Output will be displayed as:

Download Source Code: