C - Goto Statement

<<Previous

Next >>





The goto statement is used to simply change the normal flow of program. It jumps the program control to the specified label. The label is an identifier excepts c-keywords which occurs somewhere else in the given function and followed by using the colon. The labels have their own name space so they cannot clash with name of the variables and functions.

syntax
goto Label;
	-
	-
	-
	-
	-
Label:

Note:

Using of goto statement gives poor programming style and they should be avoided in general.

Following is an example C Program using goto statement.

#include<stdio.h>


int main()
{
  int a;
  for(a = 0 ; a<5 ; a++)
  {
    if(a == 3)
    goto step;
    printf("The value of a = %d\n",a);
  }
  step:
  a = a * 2;
  printf("After using goto, The value of a = %d\n",a);

  return(0);

}

When you compile and execute the above program, then you will get the following output:




<< Previous

Next >>