Computer Applications | Java | Class 9 | ICSE | 2026 Examination
Conditional Construct in Java | Class 9 | Computer Applications | ICSE
Java Nested If Else Explained with Simple Programs for ICSE Students
A nested if statement is an if-else statement written inside another if-else statement. This programming construct allows us to check multiple conditions at different levels, where the checking of inner conditions depends on whether the outer conditions are true or false.
<aside> <img src="/icons/orbit_gray.svg" alt="/icons/orbit_gray.svg" width="40px" />
Formal Definition
When an if-else statement is placed inside the body of another if-else statement (either in the if block or else block or both), it is called a nested if-else statement.
</aside>
Syntax
if (condition_1) {
*// Outer if block*
Statement1;
if (condition_2) {
*// Inner if block*
Statement2;
}
else {
*// Inner else block*
Statement3;
}
}
else {
*// Outer else block*
if (condition_3) {
Statement4;
}
else {
Statement5;
}
}
Example 1: Library Membership System
Think of a library membership system where:
This is a perfect example of nested decision-making because the type of membership check only happens after confirming eligibility.
Example 2: Discount Eligibility
Consider an online shopping discount system:
Here, the discount percentage check is nested inside the membership check.