You are on page 1of 9

Jump Statement

Three jump statements


Break, continue and return

1
Break and Continue with the nested loop

2
Break as a form goto
A break statement exits a loop before
an entry condition fails.
The break statement can also be
employed by itself to provide a form
of “goto”. The format is:
break label:

3
Example – use break to exit from loop

4
Continue - Explanation

Sometimes it is necessary to exit


from the middle of a loop.
Sometimes we want to start over at
the top of the loop.
Sometimes we want to leave the loop
completely. For Example
for (int i = 0; i < length; i++) {
if (m[i] % 2 == 0) continue;
// process odd elements... }

5
Example - continue

6
Return

It has purpose to exit from the


current method
It jumps back to the statement within
the calling method that follows the
original method call.
Example
return expression

7
Example

8
Summary

Selection Statements
 If and switch
Iteration Statements
 While, do-while, for and nested
loops
Jump Statements
 Break, continue and return

You might also like