Back to Boolean Expressions and if Statements

Lesson PreviewLesson 4 of 8 in this unit

3.4 else-if Statements

Part of Boolean Expressions and if Statements in AP® Computer Science A. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

An else-if statement extends the basic if-else structure to handle multiple conditions in sequence. It allows you to check additional conditions if previous if or else-if conditions were false, providing more than two paths of execution.

java
int number = -5;

if (number > 0) {
    System.out.println("Positive");
} else if (number < 0) {
    System.out.println("Negative");
} else {
    System.out.println("Zero");
}

Output

Negative

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for AP® Computer Science A.