Unit 2 Practice Test: Selection and Iteration

Sharpen AP Computer Science A control flow skills with Unit 2 practice tests covering if/else, while loops, for loops, nested loops, and boolean logic in Java.

Want help mastering this topic?
Work 1-on-1 with an IB expert tutor.
Book a session →

Selection and Iteration in AP Computer Science A

Unit 2 introduces control flow — the mechanisms that allow a Java program to make decisions and repeat actions. This unit is among the most heavily tested on the AP exam, appearing in both MCQ code-tracing questions and FRQ code-writing tasks.

Conditional Statements: if, else if, else

Java's if/else if/else structure allows programs to execute different code paths based on conditions. AP MCQ questions often present multi-branch conditionals and ask you to trace which branch executes for a given input. Carefully evaluating boolean expressions at each branch is critical.

Boolean Expressions and Compound Conditions

Boolean logic underpins all control flow. The AP exam tests && (and), || (or), and ! (not) operators, as well as De Morgan's Laws for simplifying or negating compound conditions. Misreading a compound condition is one of the most common sources of MCQ errors.

while Loops

A while loop repeats as long as its condition remains true. AP tracing questions require you to track variable values across each iteration. A frequent FRQ task involves writing a while loop that processes input until a sentinel value is reached.

for Loops

The for loop provides a compact syntax for iteration with an initializer, condition, and update expression. AP CSA tests standard for loops traversing integer ranges and enhanced for loops traversing arrays and ArrayLists in Unit 4.

Nested Loops

Nested loops appear frequently in AP FRQs involving 2D arrays and pattern generation. Tracing nested loops requires careful attention to which variable belongs to the outer loop and which belongs to the inner loop at each step.

Common Errors in Unit 2

FRQ Skills Built in Unit 2

Writing loops and conditionals from scratch is a core FRQ requirement. Unit 2 practice builds the habit of planning loop logic before writing code — identifying the starting value, the termination condition, and the update step before attempting to implement the loop body.

Frequently asked questions

The Unit 2 test covers selection statements (if, else if, else), iteration (for loops, while loops), and boolean logic. These control flow concepts are essential for nearly every programming task on the AP CS A exam. Questions test your ability to trace through conditional and loop logic and predict program output accurately.
Nearly every AP CS A FRQ involves loops and conditionals. Whether you are traversing an array, searching for values, or building class methods, you need solid control flow skills. Weak loop logic leads to off-by-one errors, infinite loops, and incorrect output. Mastering Unit 2 is essential for scoring well on both MCQ and FRQ sections.
Common Unit 2 errors include off-by-one mistakes in loop bounds, incorrect boolean expressions in conditionals, infinite loops from wrong update statements, and confusing AND versus OR logic. Practice tracing code by hand step-by-step to catch these errors. Careful code tracing is one of the best ways to build reliable loop and conditional skills.
Ready to start?
Book a free diagnostic.
Get started →

Related