In this tutorial, we will learn about the Jump Statements in Java, or its types, and how to use them with the help of examples.

Define Jump Statements

Jump statements are use to unconditionally transfer program control from one point to elsewhere in the program. Jump statements are primarily use to interrupt loop or switch-case instantly. 

Java supports three jump statements: 

  • Break Statement
  • Continue Statement
  • Return Statement.

Break Statement in Java

The Break Statement is use to exit the loop irrespective of whether the condition is true or false. Whenever a “break” is encountered inside the loop, the control is sent outside the loop.

Syntax

break;
Syntax of Break Statement in Java

Example of Break Statement in Java

Input Value

public class jumprbc {
    
  public static void main(String args[])
  {
      int i;
      for(i = 1; i <= 15; i++)
      {
      if (i == 10) break;
      System.out.print(i + "  ");
      }
   }

}
Example of Break Statement in Java

Let’s run the code

Input Value
Input Value

Continue Statement in Java

The continue statement is use to immediately move to the next iteration of the loop. the control is taken to the next iteration thus skipping everything below “continue” inside the loop for that iteration.

Syntax

continue;
Syntax of Continue Statement

Example of Continue Statement

Input Value

public class jumprbc {
    
    public static void main(String[] args) {   
        for(int i=5;i<=15;i++){  
            if(i==10){  
                 
                continue;
            }  
            System.out.println(i);  
        }  
    }  
}
Example of Continue Statement

Let’s run the code

Input Value

Output Value

Output Value

Return Statement in Java

The Return Statement of the return value must match the method declare return statement. we can’t return an integer value from a method whose declaration types is void.

Syntax of Return Statement in Java

return;
Syntax of Return Statement in Java

Example of Return Statement in Java

Input Value

public class jumprbc {
    
    public static int add(int x, int y){
        int sum = x+y;
        return sum;
    }
    public static void main(String[] args) {
        int a = 25;
        int b = 54;
        int sum = add(a, b);
        System.out.println("Sum x and y: " + sum);
    }

}
Example of Return Statement in Java

Let’s run the code

Input Value

Output Value

Output Value

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about JAVA Wikipedia please click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *