Course

Computer Applications | Java | Class 9 | ICSE | 2026 Examination

Chapter Playlist

Conditional Construct in Java | Class 9 | Computer Applications | ICSE

Lecture Video

Java if else Statement Explained (ICSE 9 & 10)

IF … ELSE Construct in Java

The if-else construct is a fundamental decision-making statement in Java that allows a program to choose between two alternative paths of execution based on a condition. While the simple if statement can execute code when a condition is true, the if-else construct provides dual decision-making capability—executing one block when the condition is true and an alternative block when it is false.

Real-World Analogy: Think of a traffic signal at a pedestrian crossing. If the light is green, you drive forward; else (if it's not green), you stop. You cannot do both actions simultaneously—you must choose one path based on the condition.

<aside> <img src="/icons/orbit_gray.svg" alt="/icons/orbit_gray.svg" width="40px" />

Formal Definition

The if-else statement is a bi-directional control flow construct that evaluates a boolean expression and executes one of two blocks of code: the if block when the condition is true, or the else block when the condition is false. Unlike the simple if statement, the if-else guarantees that exactly one of the two code blocks will execute.

</aside>

Syntax

if (boolean_condition) {
    *// Statement(s) to execute when condition is TRUE*
} else {
    *// Statement(s) to execute when condition is FALSE*
}

Components:

Flowchart of if … else

image.png