Copyright © Programs ++
Design by Dzignine
Friday 20 January 2012

Jump Statements

Jump statements are basically used to transfer control anywhere in the program. These include goto, return, continue and break statements. An example is given as follows : 

// Program to demonstrate the use of jump statment
#include<iostream.h>


int main()
{

    int x;
    cout<<" Enter the value of x : ";
    cin>>x; // prompts the user for input

    start : // tag for the goto statement
    cout<<" @ ";
    ++x; // prints @ until the the value of x is greated than 10
    if ( x < 10 )
    goto start; // jumps to the start tag

    // To demonstrate continue
    cout<<endl;

    while ( x > 0 )
    {
        --x; // decrements value of x

        if ( x < 10 )
        {
            cout<<" \n Hello !!!";
            continue; // continue if x is greater than 10
        }
        else
            break; // breaks the loop if x is -ve


    } // end of while
   
    return 0;
} // end of main


0 comments:

Post a Comment

Comment Here....