goto statement in C/C++


The goto statement is a jump statement. Within a function, it is used to jump from one statement to another. The use of this statement is highly discouraged. It makes the program complex and difficult to trace the control flow of program. It makes hard to modify the program.

Here is the syntax of goto statement in C language,

goto label;
.
.
.
label: statement;

Here is an example of goto statement in C language,

Example

 Live Demo

#include <stdio.h>
int main () {
   int a = 10;
   LOOP:do {  
      if( a == 12) {
         a = a + 1;
         goto LOOP;
      }
      printf("Value of a: %d\n", a);
      a++;
   }while( a < 15 );
   return 0;
}

Output

Value of a: 10
value of a: 11
value of a: 13
value of a: 14

Updated on: 24-Jun-2020

279 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements