2.3 control statements ( Jumping control structures (or) Jumps in Loops )
4) Jumping control structures (or) Jumps in Loops: -
- Jumping control statements is also known as Unconditional control statements.
- Jumping control statements are the control statements that transfer the program control from one part to another part directly, without checking any condition.
- They unconditionally jump to a specified location in the program.
- There are 4 types of jumping statements.
a) goto statement
b) break statement
c) continue statement
d) return statement
a) goto statement: -
- The goto statement is a jumping control statement which is used to transfer the control to a labelled part of the program.
- It can cause a program to jump forward or backward.
Syntax: -
Flow chart: -
Example: -
Output: -
b) break statement: -
- break statement is a jumping control statement which is used to terminate a loop or switch immediately.
- It can be used inside loops or switch statements to bring the control out of the block.
- The break statement can only break out of a single loop at a time.
Syntax: -
break;
Flow chart: -
Example: -
Output: -
c) continue statement: -
- The continue statement is a jumping control statement which is used to skip the current iteration of a loop and continues with the next iteration.
- It can be used inside loops along with the conditional statements to bypass the
remaining statements in the current iteration and move on to the next iteration.
Syntax: -
continue;
Flow chart: -
Example: -
Output: -
d) return statement: -
- The return statement is a jumping control statement which is used to terminate the execution of a function and returns a value to the calling function.
- It is commonly used to provide a result back to the calling code
Syntax: -
return expression;
Flow chart: -
Example: -
Output: -