Page 165 - CA_Blue( J )_Class9
P. 165
if-else-if statements/ladder
if-else-if statements are used in those cases where any one condition is satisfied among multiple conditions.
If condition1 is satisfied, then after executing statement 1, the control goes to the statement after the entire
if-else-if ladder. If condition 1 does not satisfy, then it checks condition 2 and depending on the result executes the
statement 2 and exits from the if-else-if ladder. This process continues until a true condition is found, after which
no further conditions are checked.
Syntax:
if(condition1){
//code to be executed if condition1 is true
}
else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
Start
Input values
a and b
true Print Both a and
if (a==b)
b equal
false
if (a!=b) true Print a and b are
not equal
false
true Print a is greater
if (a>b)
than b
false
Stop
Conditional Constructs in Java 163

