Write about Jumps in loops in java

Jumps in loops:

Break : [jumping of out of a loop]

Break is used to come out of a loop, an early exists from a loop can be accomplished by using break statement. The break statement can be used within while, do, (or for loops).

When the break statement is encounted inside a loop, the loop is immediately exited and the program continuous with the statement immediately following the loop.

When the loops are nested the break would only exist from the loop containing it. that is the break will exit only a single loop.

Syntax:

break;

Continue:[skipping a part of a loop]

During the loop operations it may be necessary to skip a part of the body of the loop under certain conditions.

Like the break statement java supports another similar statement called the continue statement.

Unlike the break the continue on the name implies causes the loop to be continued with the next iteration after skipping any statement s in between the continue statement tells the compiler skip the following statements and continue with the next iteration. The format of continue statement is as follows.

Syntax : 

continue;

In while & do loops  continue causes the control to go directly to the test condition and then to continue the iteration process.


In case of for loop the increment section of the loop is executed before the test condition is evaluated.

Related

Java 5639863438468620996

Post a Comment

emo-but-icon

item