Goto Statement


  • Unconditional Branching: SYNTAX: goto <label>
  • A label is any valid variable name and must be followed by a colon. goto read;
  • The label can be anywhere in the program either before or after the goto statement. Note that such control transfer occurs unconditionally. It is obvious that the goto breaks the normal sequential execution of the program. This is basically a control jump, which could be either forward or backward. Consider the following code,
    # include < iostream.h > 
    void main(){
    char c;
    take:
    cout << “ Input the character (z to exit) :”;
    cin >> c; 
    if (c==‘z’)
    cout << “ You have typed the right character to exit”;
    else
    { 
    cout << “character is” << c << endl;
    goto take;
    }
    }
    


Switch-case << Previous

Next >> Looping Structure

Our aim is to provide information to the knowledge seekers.


comments powered by Disqus


Footer1