AP® Computer Science A glossary

if-else statement

Also called: two-way selection, else

Course: AP® Computer Science A Shows up in: Unit 2: Selection and Iteration

A two-way selection: the if body runs when the Boolean expression is true, and the else body runs when it is false. Exactly one of them runs.

Appears in the course and exam description (CED): 2.3.A.4

The else has no condition of its own. Two separate if statements are different: both of their bodies can run.

int score = 64;
if (score >= 70) {
    System.out.println("Passed");
} else {
    System.out.println("Try again");
}

Output:

Try again
Learn it properly, with a checkpoint 2.3 if Statements

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure