Mobile Ad-Hoc Networks
Structured Query Language(SQL)
Let's Test Out
C Programming Language
HTML & CSS
Branch Statements In Java | Core Java Tutorial | Minigranth
Features of Java
First Java Program
Executing Java Program
Comments In Java
Java Data Types
Operators In Java
Loops In Java
Arrays In Java
Command Line Arguments
Recursion In Java
OOPs In Java
Classes, Methods & Objects
Inheritance In Java
Dynamic Method Dispatch
Abstraction In Java
Encapsulation In Java
Packages In Java
Strings In Java
Java String Programs
Branch Statements In Java : Introduction
There are statements which are
used to skip some parts of program
and branch the control to another area. These are called branch statements in java.
There are preferably two type of branch statements in java :
We will try to give an idea about both of these branch statements In java along with their respective flowcharts and examples.
Branch Statements In Java : The Break Statement
statement is used to come out of loop (break from loop) and from switch block.
It is handy to use in situations when we want to break the loop in between without full completing the iterations.
We have already seen the use of break statement in switch. Now let’s use break in loop. Below is the mentioned flowchart and example for it.
" can be used with any loop.
The Break Statement : Flowchart
The Break Statement : Example
The Break Statement : Output
As we can see in the output that when value of
and control comes out of the loop.
: If we use nested loop and we have break statement in the inner loop then only the inner loop breaks.
Branch Statements In Java : The Continue Statement
statement skips the part of program after
statement and continues the flow of program. It is used to continue the loop.
Below is the mentioned flowchart and example for it.
The Continue Statement : Flowchart
The Continue Statement : Example
The Continue Statement : Output
You can see in the above output :
2 is not printed
statement does it work and skips the remaining statements and continues the loop.
in nested loops , if
is used is inner loop the only inner loop is continued , no effect of continue in outer loop.