SAT / PSAT
SAT / PSAT Prep
History & Social Science
AP World History AP US History AP European History AP Human Geography AP US Government & Politics AP Psychology AP Macroeconomics AP Microeconomics
English
AP English Language & Composition AP English Literature & Composition
Math & Computer Science
AP Calculus AB/BC AP Precalculus AP Statistics AP Computer Science A AP Computer Science Principles
Sciences
AP Biology AP Chemistry AP Environmental Science AP Physics 1 AP Physics 2
World Languages & Arts
AP Spanish Language AP Art History AP Music Theory Start studying →
Unit 2 · Selection & Iteration Flashcards Cheat Sheet Essentials Visual Review MC Practice FRQ Practice

AP Computer Science A Unit 2 Essentials

The must-know terms and core concepts for Unit 2: Selection and Iteration. Every vocabulary word, operator, and idea you need to master.

← Back to Unit 2 hub
Key Concept 1
Boolean expressions drive selection
A Boolean expression evaluates to true or false, usually built with relational operators (<, >, <=, >=, ==, !=). Selection statements use these to choose which code runs: if executes a block when a condition is true, if/else chooses between two blocks, and nested if / else-if chains handle multiple cases in order. Remember to use == (not =) to test equality, and .equals() to compare objects like Strings.
Boolean if / else Relational Ops
Key Concept 2
Logical operators combine and negate conditions
Compound conditions use the logical operators && (AND), || (OR), and ! (NOT). Java uses short-circuit evaluation: in a && b it skips b when a is false, and in a || b it skips b when a is true. You can rewrite negated compound conditions with De Morgan’s laws — !(a && b) equals !a || !b, and !(a || b) equals !a && !b — and confirm equivalence with truth tables.
&& || ! Short-Circuit De Morgan
Key Concept 3
Loops repeat code, and nested loops multiply it
Iteration repeats a block of code. A while loop repeats as long as its condition is true (good for open-ended repetition), and a for loop bundles initialization, condition, and update for counting. Loops power String traversals and standard algorithms. A nested loop runs its inner loop fully for each outer iteration — two n-loops give n² executions. Watch for infinite loops and off-by-one errors, and use informal run-time analysis to count executions.
while / for Nested Loops Run-Time
Boolean expression
An expression evaluating to true or false.
Boolean
Relational operator
< > <= >= == != comparing two values.
Boolean
== vs. =
Equality test vs. assignment.
Boolean
if statement
Runs a block when a condition is true.
Selection
if/else statement
Chooses between two blocks based on a condition.
Selection
Nested if / else-if
Conditions checked in order; first true branch runs.
Selection
Logical AND (&&)
True only when both operands are true.
Logic
Logical OR (||)
True when at least one operand is true.
Logic
Logical NOT (!)
Reverses a Boolean value.
Logic
Short-circuit evaluation
Stops evaluating once the result is determined.
Logic
De Morgan’s laws
!(a&&b)=!a||!b; !(a||b)=!a&&!b.
Logic
while loop
Repeats a body while its condition is true.
Iteration
for loop
Loop with initialization, condition, and update.
Iteration
Loop control variable
The counter/variable that drives a loop.
Iteration
Infinite loop
A loop whose condition never becomes false.
Iteration
Off-by-one error
Looping one time too many or too few.
Iteration
Nested iteration
A loop inside another loop.
Iteration
String traversal
Visiting each character of a String with a loop.
Algorithms
Informal run-time analysis
Counting how many times statements execute.
Algorithms