Showing posts with label continue and return control statements. Show all posts
Showing posts with label continue and return control statements. Show all posts

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

Saturday, 2 February 2013

Introduction to Control Statements in Java

Control statements decide flow of a program


if, if-else, switch, nested if, switch, for, while, do-while, break, continue and return control statements

Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.
In Java, control statements can be divided under the following three categories: