Jump Statement in C/Cpp

2 min read

The jump statements unconditionally transfer program control within a function.

C++ has 4 jump statements: return, goto, break,continue.Of these, return and goto may be used anywhere in the program whereas break and continue are used inside smallest enclosing like loops etc.

The return statement

The return statement is used to return some value from a function.as discussed earlier void is used with a non-returning function.

The goto statement

It can transfer the program control anywhere in the program.Its target destination is marked by a label (can be named anything apart from keywords.)


 goto label;


int main()
    int i=1;
Start:               // label
if(a<=50)goto start;    
    return 0;        // return statement

The following programs prints 1-50 numbers and then if checks if i is less than 50, the control goes to label ‘start’ otherwise control goes to next statement.

The break statement

A break statement skips rest of the loop and jumps over to statement following the loop.


Example of break statement

This example jumps out of the loop when i is equal to 4.

The continue statement

Continue statement also skips over a part of code.But instead of forcing termination of loop, it forces next iteration to take place.


Example of continue statement

This example skips the value of 4, and print rest of the values.

If you liked my article please follow me on @priya123 to get latest articles by me.

Choose your Reaction!
Leave a Comment