What is Jumping Statements ?
Jumping statements in Java are used to transfer the control of execution from one part of a program to another part.
Types of Jumping Statements:
break
continue
return
Break :
Break is used to terminate a loop immediately.
Example:
public class Break {
public static void main ( String [ ] args ) {
for ( int i = 1 ; i <= 5 ; i ++ ) { System . out . println ( "Iteration no :" + i ) ; if ( i == 3 ) { break ; } } }
}
Enter fullscreen mode
Exit fullscreen mode
Output:
Iteration no :1 Iteration no :2 Iteration no :3
Enter fullscreen mode
Exit fullscreen mode
The initial value of i is 1.
When the value of i becomes 3 (i==3) , the if condition is true.
So , the break statement terminates the loop immediately.
Therefore , 4 and 5 are not printed.
Continue:
Continue is used to skip the current iteration of the loop and moves to the next iteration.
It does not terminate the entire loop.
Example:
public class Continue {
public static void main ( String [ ] args )…