C++ Goto Statement

Goto statement in C++ Language is used for altering the normal sequence move control to some another part of the program.


Syntax

goto title_goto;
... .. ...

title_goto:

statement;
... .. ...

Example:

#include <iostream>
using namespace std;

int main()

{
    for (int num = 1; num <= 5; num++)
    {
        if ( num == 2 )
        {
            goto error;
        }
        cout << num << "\n";
    }
    error:
    char error[]="Number 2 Error founded";
    cout<<error;
    return 0;

}
Output:









<< C++ continue Statement         --       C++ Functions >>