C++ Jump Statements

C++ Jump Statements


C++ Jump Statements
Jumping statement unconditionally transfer program control within a function. C++ language provides us multiple statements through which we can transfer the control anywhere in the program.
There are jump statement is as follows:
  1. Break 
  2. Continue
  3. goto
  4. return
 
i.Break 
In Computer Programming, The break statement terminates the loop immediately when it is encountered, simply comes out of the loop. Immediate after the closing brace of theloop will be executed. 
The Syntax of the Break statement is as follows:
                   Break;
 
Example
Output
 
ii. Continue Statement 
 
The continue statement skips some statements inside the loop. Loop will be restarted when continue is encountered.
The Syntax of the continue statement is as follows:
                    Continue;
Output
iii. Return Statement 
 
C++ The return keyword returns a value after completing its assigned task. Only stored in the variable is passed to the function.
Example :
http://web.webdesigninghouse.com/admin/upload/699040042_rk.png
Output :
http://web.webdesigninghouse.com/admin/upload/2024704470_rk%20output.png
iv. goto Statement 
  • It is well known as ‘the jumping statement’. It is primarily used to transfer control of execution to any place in a program. It is useful to provide branching within a loop.
  • When the loops are deeply nested that if an error occurs then it is difficult to get excited from such loops. A Simple break statement cannot work here properly. In this situation, a goto statement is used. A goto statement in the C++ programming language provides an unconditional jump from goto a labeled statement in the same function.
The Syntax for goto statement is as follows:
goto label;
..
.
label statement;
Here Label can be any pain text except the C++ keyword and it can be set anywhere in the C++ program above.
Example
  
Output