goto statement in C++

We will learn about goto statement in C programming and how this statement alters the sequential flow of the program execution.

goto statement

goto statement in C++ programming

Syntax of got statement:

goto label;
... .. ...
... .. ...
... .. ...
label: 
statement;

Here, label indicates the location. goto tells the program to jump the code to the location of label and start executing program from that line.

Example of goto statement

# include <iostream>
using namespace std;
int main ()
{
  goto a;       //instructs compiler to jump to label a
  b:  
    cout << "gram";
    goto c;        //instructs compiler to jump to label c
  a:
    cout << "C pro";
    goto b;       //instructs compiler to jump to label b
  c:
    cout << "ming";
   return 0;
}

As you can see in above program the code is buggy and hard to follow. If and only if goto statement simplifies the program you are creating and is also easier for your co-worker to understand the code easily then use goto statement.