Home C-tutorials C Goto Statement
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

C Goto Statement

Advertisement
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:

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 5, 2009

Ask Questions?    Discuss: C Goto Statement   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
gaurav verma
April 16, 2011
structure

define in details
gaurav verma
April 16, 2011
structure

define in details
Rahul Nandan
May 26, 2011
Goto function

Usage of "label statement" is not clear.
sumayya Turab
June 9, 2013
c,c++

thanks i understood the usage of goto statement.
sumayya Turab
June 3, 2013
c,c++

i want to becum perfect in programming.so what i have to do..i love programming..
praveen nishchal
October 8, 2011
Scope of goto in C

Hi, I was asked a question which was something lyk dis: int main(void) { {int i=10; goto lbl;} {int i=20; {int i=30; lbl:;} printf("%i", ++i);} } does lbl has a gloabl or function or local scope inside a c pgm?
gowtham
November 3, 2011
information technology

Itsits very useful
binod yadav
February 28, 2013
programming c

learn is programming c
venkat giri.p
January 25, 2012
c pprograming

i need the programs in c program using all the functions. mail it to my mail id
rohini
April 30, 2012
play fun games

very nice and very beautiful of the play
ANAS
August 6, 2012
c

c is not intresting, how can we change it?
Joshua
August 20, 2012
Thanks

Very short and useful and get's right to the point. Figured out how to use the "Goto" statement in 1 minute. Thank You
Raj
December 15, 2012
programming in c

Array, function and pointer
vikas rana
October 20, 2012
example of forward goto statement...

please help me...........
Adarsh
October 26, 2012
Goto-c

More examples are needed
DMCA.com