Loading...

Java essentialsControl flow

Conditionals

6 min lesson

Next

An if statement evaluates a boolean expression and chooses which block to run. else if handles additional cases, and else provides a fallback.

Keep in mind

Use braces around branches and make each condition easy to read.

Lesson.java
int score = 82;

if (score >= 90) {
    System.out.println("Great work");
} else if (score >= 70) {
    System.out.println("Passed");
} else {
    System.out.println("Keep practicing");
}

What happens: Passed

Previous
Next