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 Cheat Sheet

A one-page visual summary of Selection and Iteration — every operator, statement, loop pattern, and exam trap you need, on a single screen.

← Back to Unit 2 hub

The basics

What it covers: Boolean expressions, if/else and nested selection, logical operators and De Morgan’s laws, while and for loops, nested iteration, String algorithms, and informal run-time analysis.

Exam weight: About 25–35% of the multiple-choice section — one of the largest units.

The big question: How do programs make decisions and repeat actions?

Computational thinking practices: Design Code, Develop Code, Analyze Code, Document Code, and Use Computers Responsibly.

Key topics at a glance

Relational Operators

< > <= >= == != compare values and produce a boolean. Use == to test equality, = to assign.

if / if-else

if (cond) { } runs the body when true; if (cond) { } else { } runs exactly one branch.

Nested & else-if

Chain conditions with else if; the first true branch runs and the rest are skipped.

Logical Operators

&& (AND: both true), || (OR: at least one true), ! (NOT: flips). Short-circuit: evaluation stops once the result is known.

De Morgan’s Laws

!(a && b) = !a || !b and !(a || b) = !a && !b. Use to simplify negated conditions.

while Loop

while (cond) { } repeats while the condition is true. Must make progress or it becomes an infinite loop.

for Loop

for (init; cond; update) { }. Example: for (int i = 0; i < n; i++) runs n times (i = 0..n−1).

Nested Iteration

A loop inside a loop; inner runs fully for each outer pass. Two n-loops → inner executions.

The key terms and rules you must know

Key themes to remember

Common exam traps