AP® Computer Science A glossary
if statement
Also called: one-way selection
Course: AP® Computer Science A Shows up in: Unit 2: Selection and Iteration
A selection statement that runs its body only when its Boolean expression is true, changing the flow of control.
Appears in the course and exam description (CED): 2.3.A.22.3.A.3
Always use braces: without them, only the next single statement belongs to the if. A semicolon right after the condition gives the if an empty body.
int battery = 15;
if (battery < 20) {
System.out.println("Low battery");
}
Output:
Low battery Learn it properly, with a checkpoint 2.3 if Statements