Home C-tutorials C Goto Statement



C Goto Statement
Posted on: February 5, 2009 at 12:00 AM
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

     

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:

Related Tags for C Goto Statement:
cfunctionfuniolabelstateintpoiuncwithgotostatementtopointeitnotfrominnostamntpsthinjumpjemfuncmewhichsatkmarkismpsgoarstatssthstababelgotonomo


More Tutorials from this section

Ask Questions?    Discuss: C Goto Statement   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.