Search⌘ K

The if-else Structure

Explore the if-else structure in Java to understand how to make decisions within your code by executing specific statements depending on whether a condition is true or false. Learn to write conditions that control program flow, and practice with examples that distinguish even and odd numbers to gain confidence in using conditional logic for your AP Computer Science A exam.

We'll cover the following...

What is an if-else statement?

Think about the term if-else in real life. Here is a common phrase:

Java offers a two-way selection process. There are two sets of statements: one to be executed when the boolean condition is true, and another set for when the boolean condition is false.

Explanation

In this case, the body of the if is executed when the boolean ...