Else statement

Else statement — works with the if statement to provide an alternative block of code to execute if the if condition is false.

if (condition) {
    // Code to execute if the condition is true
} else {
    // Code to execute if the condition is false
}
int age = 16;
if (age >= 18) {
    System.out.println("You are an adult.");
} else {
    System.out.println("You are not an adult.");
}

Related concepts

Else statement — Structure map

Clickable & Draggable!

Else statement — Related pages: