AP® Computer Science A glossary

Multiway selection

Also called: if-else-if, else if

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

An if-else-if chain that runs at most one segment of code: the one for the first expression that evaluates to true, or the trailing else if none is true.

Appears in the course and exam description (CED): 2.4.A.3

Order matters: once one expression is true, the rest of the chain is skipped. Without a trailing else, it is possible that no segment runs.

int score = 84;
if (score >= 90) {
    System.out.println("A");
} else if (score >= 80) {
    System.out.println("B");
} else {
    System.out.println("C or below");
}

Output:

B
Learn it properly, with a checkpoint 2.4 Nested 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