AP Computer Science A Practice Quiz: if Statements
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) To repeat a segment of code a specific number of times.
B) To store data in a variable for later use.
C) To change the sequential execution of statements based on a condition.
D) To group related code into a reusable block called a method.
Correct Answer: C
The content states, 'Selection statements change the sequential execution of statements.' This means they alter the normal top-to-bottom flow of a program.
A) Only when the associated Boolean expression evaluates to true.
B) Only when the associated Boolean expression evaluates to false.
C) It is always executed, regardless of the Boolean expression.
D) It is executed once if the expression is true and twice if it is false.
Correct Answer: A
The provided content specifies that for a one-way selection (if statement), 'The body is executed only when the Boolean expression is true.'
A) A one-way selection (if statement)
B) A two-way selection (if-else statement)
C) Sequential execution
D) A variable declaration
Correct Answer: B
This scenario requires two different actions based on the condition (password is correct or not). The content states that a two-way selection (if-else) is used 'when there are two segments of code—one to be executed when the Boolean expression is true and another segment for when the Boolean expression is false.'
A) Hot
B) Day
C) Hot Day
D) Nothing is printed.
Correct Answer: C
The Boolean expression `temperature > 90` (95 > 90) is true. Therefore, the body of the if statement is executed, printing 'Hot'. The program then continues its sequential execution and prints the next statement, ' Day'.
A) Pass
B) Complete
C) PassComplete
D) Nothing is printed.
Correct Answer: B
The Boolean expression `score > 60` (50 > 60) is false. Therefore, the body of the one-way if statement is skipped. The program continues its sequential execution and prints 'Complete'.
A) Even
B) Odd
C) EvenOdd
D) The code produces an error.
Correct Answer: A
The Boolean expression `x % 2 == 0` checks if x is even. Since 20 divided by 2 has a remainder of 0, the expression is true. The code inside the `if` block is executed, printing 'Even', and the `else` block is skipped.
A) Quiet
B) Loud
C) QuietLoud
D) Nothing is printed.
Correct Answer: A
The variable `isAsleep` is true, so the Boolean expression in the if statement is true. Consequently, the first block of code is executed, printing 'Quiet', and the else block is ignored.
A) One-way selection uses an `if`, while two-way selection uses a `while` loop.
B) One-way selection executes code for a true condition, while two-way selection executes code for both true and false conditions.
C) One-way selection can only check integer values, while two-way selection can check Boolean values.
D) One-way selection is for branching processes, while two-way selection is for sequential processes.
Correct Answer: B
Based on the content, a one-way selection (`if`) executes a code segment only when a condition is true. A two-way selection (`if-else`) provides two segments of code: one for when the condition is true and another for when it is false.
A) An arithmetic expression
B) A string expression
C) A method expression
D) A Boolean expression
Correct Answer: D
The provided text explicitly mentions that selection statements execute code based on a 'Boolean expression' being true or false.
A) Low
B) OK
C) LowOK
D) The code will not compile.
Correct Answer: B
First, `balance` is updated: `balance = 100 - 50`, so `balance` becomes 50. The if statement then checks the condition `balance < 50`. Since 50 is not less than 50, the condition is false. Therefore, the code in the `else` block is executed, printing 'OK'.