Unit 2 · Selection and Iteration
Short-Circuit Logic
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What short-circuit logic covers
Java short-circuits both && and ||. If the left operand of && is false, the right operand is never evaluated, because the result is already known. If the left operand of || is true, the right operand is skipped. This is not just an optimization: it is a guard. Writing i < arr.length && arr[i] == target prevents an index out of bounds error that the reversed order would cause.
Where students lose points
When the right operand contains a method call or an increment, students count side effects that never actually happen. They also reverse guard conditions, putting the array access before the bounds check, which throws at runtime even though the condition "looks" correct.
How it shows up on the AP exam
Unit 2 material tested through counter variables and print statements inside the second operand. The guard pattern is also exactly what FRQ array and ArrayList traversals require to avoid runtime exceptions.
For practice use only.
Short-Circuit Logic MCQ Practice
AP CSA short-circuit evaluation practice: when && and || stop evaluating, why operand order prevents errors, and how side effects change the result.
Answered 0 of 15
Choose one answer.
