Skip to main content

AP Computer Science A Unit 2 Cheatsheet: Selection and Iteration

AP Computer Science A Unit 2 Cheatsheet: Selection and Iteration

Start with the first 3 sections of the Unit 2 one-page cheatsheet below. The full sheet is a PDF you can print.

Algorithm Building Blocks

Three core components:

  • Sequencing: statements execute in order
  • Selection: choice based on true/false condition
  • Repetition: process repeats until outcome reached

Order matters—changing the sequence of statements, where a selection (if) is placed, or a loop's condition can change the algorithm's result, so trace the code carefully (though some changes, like reordering independent statements, leave the result the same).

Relational & Boolean Operators

OperatorUse
==, !=equality (primitives: values; references: object identity)
<, >, <=, >=numeric comparison
!NOT (flips boolean)
&&AND (both true)
||OR (at least one true)

Precedence: ! → && → ||

Short-circuit: && and || stop evaluating once result is determined.

for Loops

Three parts:

  1. Initialization: executed once before first evaluation
  2. Boolean expression: evaluated before each iteration
  3. Update: executed after body, before next evaluation

Loop control variable: initialized in part 1, typically incremented in part 3.

Equivalence: any for loop can be rewritten as while loop (and vice versa).

Trace execution order: init → test → body → update → test → …

The rest of the Unit 2 sheet

6 more sections are on the one-page PDF:

  • if & if-else Statements

  • Nested Iteration & Execution Count

  • Standard Algorithms: Numbers & Strings

  • Nested if & De Morgan's Law

  • while Loops

  • Common Tracing & Design Patterns

Made by you

Visual Cheatsheets

Pick a Unit 2 topic and a format: flowchart, comparison chart, vocab sheet, Cornell notes and more. Ready in about a minute.

Printable PDF · from the Fiveable shop

AP Computer Science A Unit 2 Cheatsheet

1 page · Selection and Iteration · PDF

Visual Cheatsheets

One topic, the format you pick, ready in about a minute

Format

Topic

Takes 30–60 seconds

Preview: Standard

Unit 2: Selection and Iteration, topic by topic

Each topic has a full study guide. See the whole unit.