Boolean Expressions: every key term you need (+ practice quiz)
54 flashcard terms for AP Computer Science A Unit 3, written to match the course framework. Read them here, drill them as flashcards, or take the 42-question quiz. Free, no account needed.
Only the first true branch executes; subsequent conditions are skipped. Order matters when ranges overlap (test the narrowest or highest threshold first).
Sequential ifs vs else-if
Separate if statements each get tested and several may run; an else-if ladder runs at most one branch. Choosing the wrong form causes double counting.
Boolean Identity Simplification
if (flag == true) simplifies to if (flag); if (flag == false) to if (!flag). Comparing booleans to literals is redundant.
Return Boolean Directly
Instead of if (x > 0) return true; else return false; write return x > 0;. Boolean expressions are values.
Truth Table Reasoning
To prove two boolean expressions equivalent, evaluate both for every combination of inputs (4 rows for two variables, 8 for three). Any differing row disproves equivalence.
Range Test
lo <= x && x <= hi checks membership in a closed interval. Java has no chained comparison; lo <= x <= hi does not compile.
Exclusive Or Pattern
a != b on two booleans is true when exactly one is true. Equivalent to (a || b) && !(a && b).
Equality of Object References
Using == on two objects tests identity, so two equal-content objects can fail the test. Classes define equals to compare state.
Testing for null First
Always test obj != null before calling methods on obj in a compound condition; place it leftmost so short-circuiting protects the call.
Ternary-free Subset
The AP CED does not include the ?: conditional operator; write an explicit if/else instead. You may still see it in code you read outside the exam.
Nested if Simplification
if (a) { if (b) doIt(); } equals if (a && b) doIt(); provided there is no else attached to either if.
Off-by-one in Thresholds
score >= 90 versus score > 90 differ exactly at 90. Read boundary conditions in the problem statement carefully; the exam loves boundary values.
Boolean Variables as Flags
boolean found = false; set to true when a condition is met, then test after a loop. Avoid resetting it to false inside the loop unless intended.
Operator Precedence for Booleans
! binds tightest, then relational (<, >), then equality (==, !=), then &&, then ||. a || b && c means a || (b && c).
Equivalence Testing of Conditions
Two boolean expressions are equivalent when they agree on every row of the truth table; testing a few sample values can only disprove equivalence, never confirm it.
Number of Truth Table Rows
An expression with n distinct boolean variables has 2^n rows, so three variables require eight cases for a complete check.
Absorption Law
a || (a && b) simplifies to a, and a && (a || b) simplifies to a, because the extra clause can never change the outcome.
Distribution Over Boolean Operators
a && (b || c) equals (a && b) || (a && c), which is how nested conditions get flattened into a single test.