C++ Jump Statements
Jump statements are used to manipulate the course 'of the program, if some conditions are met.
In C++ there are 4 jump statements continue, break, return and goto.
Let us look into each of them in more detail.
Continue
It is used to execute other parts of the loop while skipping some parts declared inside the condition, rather than terminating the loop, it continues to execute the next iteration of the same loop.
Consider the following example to understand better.
Caution : continue is used to continue remaining statements of a loop in case an if statement is encountered in a statement. Use it when the loop to go through other else if statements even after the first if condition is met.
Break
It is used to terminate the whole loop if the specified condition is met. Unlike the continue statement once the condition is met, break breaks the loop and the remaining part of the loop is not executed.
Consider the example given below.
Return
It takes control out of the function. It is stronger than break. It is used to terminate the entire function after the execution of the function or after some condition. Every function has a return statement with some returning value except the void()function.
Consider a second example
Goto
This statement is used to directly jump to that part of the program to which it is being called. Every goto statement is associated with a label that takes them to part of the program for which they are called. The label statements can be written anywhere in the program it is not necessary to use before or after the goto statement. This statement makes it difficult to understand the program hence it is considered dangerous must be avoided.
Consider this example to better understand goto statements:
Caution: goto statement is a very tricky and dangerous statement, using it leads to unwieldy programs. It is considered a poor programming practice