Jump Statements in C++ language :

Jump Statements :

The jump statements unconditionally transfer program control within a function. C++ has four statements that perform an unconditional branch : return, goto, break and Continue. Of these, you may use return and goto anywhere in the program whereas break and continue are used inside smallest enclosing like loops etc. In addition to the above four, C++ provides a standard library function exit() that helps you break out of a program.

The return Statement

The return statement is used to return from function. this statement will be explained in details under chapter 'Functions'.

The goto Statement

The goto statement is rarely used in programming today yet we are discussing goto as it is provided by C++ and without discussing it we cannot say the jump statements have been covered.
A goto statement can transfer the program control anywhere in the program. The target destination of a goto statement is marked by a label. The target label and goto must appear in the same function. For example the following code fragment prints numbers from 1 to 50:

if(a<50) goto start;

The break statement :

The break statement enables a program to skip over part of the code. A break statement terminates the smallest enclosing switch statement. Execution resumes at the statement immediately following the body of the terminated statement. For example the following code fragment if case 1 is true(1) then stop loop execution :

case 1:
cout << " You chose One" << endl;

The continue Statement :

The continue is another jump statement like the break statement as both the statements skip over a part of the code. For example the following code fragment a=1; is true(1) so, print true value but continue execute next lines and print also false value:

{ cout<<"true value"; continue}
else { cout<<"false value"; }

Computer Science Engineering

Special Notes

It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.

CSE Notes