Jumping Statements in Java

In this tutorial we will learn about Jumping statements in Java. Jumping statements are also part of control statements in Java. Jumping statements are use to send execution control to specific statement in Java. In this tutorial we will learn three jumping statements in Java.

  • break
  • continue
  • return

Jumping Statements in Java


break statement: Break statement is use to break the normal flow of execution control. we use break statement normally with switch statements in cases and in loops to break loop based on specific condition. Always keep in mind we can not use break statement outside the loop or switch statement.

Example
   
class BreakExample
{
   public static void main(String[] args){
    for(int i=0; i<10; i++){
        if(i==5){
            break;
        }
        System.out.println(i);
     }
    System.out.println("outside of for loop");
   }
}
   


continue statement: Continue statement with loops. It is so simple when continue statement encountered it simply skip current iteration of loop and move to next iteration. If there is any other statement after continue statement that will not execute. Check this example.

Example
  
  class ContinueExample
     {
     public static void main(String[] args){
       for(int i=1; i<=10; i++){
         if(i==5||i==7){
            continue;
          }
        System.out.println(i);
      }
    }
}
 


return statement: Return statement we use with methods in java. Main motive of return statement is to return value to its caller. Check this example.

Example
 
 class ReturnExample
   {
    public static void main(String[] args){
      int result =  new ReturnExample().sum(10,15);
      System.out.println("Result is = "+result);
     }

     int sum(int a,int b){
      return a+b;
     }
}
 




Share this tutorial with your friends on your social Media..

Jumping Statements in Java Jumping Statements in Java Jumping Statements in Java Jumping Statements in Java



Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.


Owlbuddy.com