Java control statements cause the flow of execution to advance and branch based on the changes to the state of the program.
Control statements are divided into three groups:
Control Flow in Java Programing |
- Selection statements allow the program to choose different parts of the execution based on the outcome of an expression
- Iteration statements enable program execution to repeat one or more statements
- Jump statements enable your program to execute in a non-linear fashion
Selection Statements:
Java selection statements allow to control the flow of program‘s execution based upon conditions known only during run-time.Java provides four selection statements:
- if
- if-else
- if-else-if
- switch
Iteration Statements Java iteration statements enable repeated execution of part of a program until a certain termination condition becomes true.Java provides three iteration statements:
- while
- do-while
- for
Syntax for While:
while(Condition)
{
i++
}
Syntax for While:
do{
i++
}while(condition);
Jump Statements Java jump statements enable transfer of control to other parts of program.Java provides three jump statements:
- break
- continue
- return
In addition, Java supports exception handling that can also alter the control flow of a program.