Goto Statement in C++

Goto statement provide a jump without any condition to the goto specific label in a function. Through goto stalemate we also make our program infinite . But goto statement leave badly impact on the flow of program and programmers and developers recommend to avoid it.

Source Code

#include<iostream> 
 using namespace std;
int main() 
{
 string name ;
 int  ID ;
 string job;
 char choice;
 welcome:cout<<endl;
 cout<<" Enter Your Name : ";
 cin>>name;
 cout<<" Enter Your ID   : ";
 cin>>ID;
 cout<<" Enter Your Job Title : ";
 cin>>job; 
 cout<<" Do You want to Stay with us?  Y/N : ";
 cin>> choice;
 if (choice == 'Y')
 {
  goto welcome;
 }
 if (choice == 'N')
 {
  return 0;
 } 
 }

Output of the Program

Goto Statement in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment