Goto-Statement-In-C++ .

In this session i have discussed goto statement in C++ .


The goto statement is used to jump the control in specified location . You have need to define the label where you want to transfer the control . These day avoid the use of goto because it is make the program less readable .


goto syntax

    label : //define the label 
    
    goto label;//send the control to label
    

Example : Write a program that will demonstrate the goto statement . In the below program you will supply the even number execution will continue other wise stop .

    #include<iostream>
    using namespace std;  
    int main()
    {          
            int x;
            label :
            cout<<"Enter the number";
            cin>>x;
            if(x%2==0)
            {
               goto label;

            }
            return 0;
    }
    
    OUTPUT : Enter the number :2
             Enter the number :4
             Enter the number :5
    

Welcome to AndroidATPoint.

back image                     next image