Construction. if statements

[comp1110-0F]

Conditionals are a way for control flow to branch — based on a certain condition, we will either execute one branch of code or another. The most common conditional in Java is the if statement.

if (condition) { IO.println("condition is true!"); } else { IO.println("condition is false!"); }

The else branch in the above code sketch is optional.

bars magnifying-glass caret-down plus minus arrow-right xmark