AP CSA 2.3 Exercise 2: if Statements Applied Practice

Unit 2: Selection and Iteration · Lesson 2.3 · Exercise 2

if Statements: Applied Practice

Six scenarios on which branch actually runs, and the two punctuation habits that silently detach a body from its condition.

How this one is different

The exercise-1 editor asks you to write branches. These six ask what runs when, because an if that compiles and does the wrong thing never announces itself.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Analyze
A student writes if (score > 90); then a print statement on the next line, indented.
What does the print statement do?
Incorrect. It runs unconditionally, not never.
Incorrect. An empty statement is legal, which is exactly why this is dangerous.
Incorrect. The empty statement is the entire body of the if.
Correct. Correct, and indentation is the trap: it shows the intent while the semicolon decides the behavior.
Question 2 of 6Apply
A grading chain is written as three separate if statements: if (s >= 90) A, if (s >= 80) B, if (s >= 70) C.
What does a score of 95 print?
Incorrect. All three conditions are true for 95.
Incorrect. That would require else if, which makes the tests mutually exclusive.
Correct. Correct. Independent ifs do not know about each other.
Incorrect. All three run, not just the last.
Question 3 of 6Analyze
The same grading chain is rewritten with else if, but ordered lowest threshold first: if (s >= 70) C, else if (s >= 80) B, else if (s >= 90) A.
What does a score of 95 print?
Incorrect. The A branch is never reached.
Correct. Correct. An else if chain must run from most restrictive to least, and this is the bug that ordering causes.
Incorrect. The code is perfectly legal; it is just wrong.
Incorrect. The chain stops at the first true test, which is C.
Question 4 of 6Apply
A student omits braces and writes an if followed by two indented statements.
What is the effect?
Correct. Correct, and this is the second silent detachment after the stray semicolon.
Incorrect. The first still runs when the condition holds.
Incorrect. A braceless single-statement body is legal.
Incorrect. Without braces, the body is exactly one statement.
Question 5 of 6Evaluate
Two versions of a method differ only in that one uses if/else and the other uses two independent ifs with opposite conditions.
When do they behave differently?
Incorrect. Compound conditions behave the same way in both forms.
Incorrect. Sign has nothing to do with it.
Incorrect. They are equivalent only while the tested value is untouched.
Correct. Correct. This is the real distinction and it is easy to miss when reading quickly.
Question 6 of 6Apply
A method must return "positive", "negative" or "zero" for an int.
How many conditions are strictly required?
Incorrect. Three outcomes need at most two tests.
Incorrect. Testing the third case is redundant work that also risks a gap if the tests disagree.
Correct. Correct. A final else is exhaustive by construction and cannot leave a value unhandled.
Incorrect. One condition can only split the values two ways.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]