Go To Example
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<< "Simple goto Example" << endl;
goto show;
cout<< "This line is not displayed" << endl;
show:cout<< "Value of p : " << p << endl;
/* goto can be used to stop the execution of a loop like the following code. */
for(int i=0;i<5;i++)
{
if(i==3)
{
goto stop;
}
else
{
cout<< "Value :" << i << endl;
}
}
stop:cout << "Loop has been stopped";
return 0;
}
Output:
Simple goto Example
Value of p : 10
Value :0
Value :1
Value :2
Loop has been stopped