C++ Goto


In C++ language jump statement is called as goto statement.


Goto statement used as the unconditional jump from the labeled goto statement in the same function.


The label is an identifier in syntax. When goto statement is occurred, control of the program jumps to label: and starts executing the code.

C++ goto

 

  • It is used for the unconditional jump.
  • It makes difficult to trace the control flow of the program.
  • The statement should avoid in order to make the smoother program.

Syntax:-

#include <iostream>   
using namespace std;
  
int main(){   
    int i=0;  
    for(i=1;i<=5;i++){   
        goto num;
    }  
    num:
    cout << "Goto Onlinetpoint" << endl;  
    return 0; 
}

notepad
It is highly discouraged because it makes difficult to trace the control flow of the program and making hard to understand and modify. If any program uses the goto can be rewritten so that it does not need the goto.



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.