Tuesday, June 14, 2016

Jump Statement

Jump statement is used to control program flow. More precisely, to move the program execution to the line of code that we want. In Java, there are three jump statements: break, continue, and return.

break


By using break statement, we can stop certain repetition process regardless defined condition or the rest of the statement contained in the loop block. This means that, when we put the break statement at loop block, the repetition will be immediately terminated and program execution will continue to the section of code below the corresponding loop structure, for example, take a look at the following program:.

class BreakDemo {
   public static void main(String[] args) {

      for (int i=0; i<10; i++) {
         if (i == 5) {
            break; //exit from loop block
         }
         System.out.println("row-" + i);
      }
      System.out.println("Statement after loop block");
   }
}


The program above will give the following result:

row-0
row-1
row-2
row-3
row-4
Statement after loop block

As shown in the above result, the program will stop the repetition when the variable i is worth 5, regardless to consider the condition (i < 10) as defined in the loop structure. The rest of statement contained in the loop block will not be executed again. After dialing break statement, the program will exit from loop block. The above provision also apply to the other loop structure: while and do-while.

continue


Like another programming language, Java provides continue statement that used to force the program to continue of loop process. continue statement can be regarded as the opposite of the break statement.

return


In Java, return statement is used to exit from code execution that contained in a method. Method will be explained further in the next post.

2 comments:

  1. Thank you for sharing valuable information with us.

    Java web application is a type of free programming language used to develop applications and software that are becoming highly in demand on the internet. The software engineer can provide the web application or software in the form of windows, Linux, and MAC OS. There are various types of systems that can not work without java and it is getting necessary day by day even the world’s no.1 application depends on java. Java has become a most popular feature in android smartphone applications that's why Aptech learning provides java training in Dwarka, Janakpuri, and in Gurgaon also. Java training helps to get you complete knowledge about web frameworks, Java testing tools, and design patterns in java.

    Let's get learn about the PHP training course
    PHP is a type of programming language that is most commonly used in dynamic functions such as modifying, collecting, and deleting all types of databases It also helps to encrypt all types of data in the form of HTML and XML file. Aptech learning provides you with a complete PHP training course at a reasonable cost that will help you to grow more in the era of the software industry.

    For more details please visit our website : Aptech Gurgaon

    ReplyDelete