Advertisement
goto label ;
// C++ The goto statement example
#include<iostream>
int main()
{
int age = 16;
if(age<21)
goto Under21Team;
else
cout<<"Welcome to Senior Team \n";
Under21Team:
count<<"The program has ended";
return 0;
}// main method ends and so does the program
The program has ended
Advertisement
// C- The goto statement
#include<iostream>
int main()
{
int age = 23;
if(age<21)
goto Under21Team;
else
cout<<"Welcome to Senior Team \n";
Under21Team:
count<<"The program has ended";
return 0;
}// main method ends and so does the program
Welcome to Senior Team
The program has ended
// C++ goto statement to go out of the loop
#include<iostream>
int main()
{
int counter = 10;
while(counter>=0)
{
counter=counter-1;
cout<<"Counter : " << counter <<"\n";
if(counter==4)
goto ExitingLoop;
}
ExitingLoop:
cout<<"We are out of the loop at the counter 4";
return 0;
} // main method ends and so does the program
Counter : 9
Counter : 8
Counter : 7
Counter : 6
Counter : 5
Counter : 4
We are out of the loop at the counter 4
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement