Saturday, 9 April 2016

Jump Statements in Java

Java Jump Statements : break, continue and return


               Java supports three jump statements. They are

                          1. break
                         2. continue
                         3. return

1. break:


               break statement in Java can be used in three ways. Other-words, the break statement has three used in the application. They are as follows

  • It terminates a statement sequence in a switch statement.
  • break statement is used to exit from a loop.
  • It can be used for a goto form of operation as Java doesn't have a goto keyword/statement as its own.


2. continue:


               continue statement is used to force an early iteration in a loop. i.e, if you wish to discard the remaining code part inside a loop and go back to the iteration part, the continue statement will do the job for you. In while and do-while loop, the continue statement transfer control directly to the condition expression of the loop

               In the case of for loop, control goes first to the iteration part and then transfer to the condition expression. 

Example program for continue statement in Java

3. return:


               The return statement is used to explicitly return from a method. The return statement can be used to terminate from a method and return control to its caller position. 

Example program for return statement in Java

No comments :

Post a comment