Welch Teaching & CoachingComputer Science · AP CSP
← AP CSP Unit Hub
AP COMPUTER SCIENCE PRINCIPLES · UNIT 3

Pseudocode, Logic & Control Structures

Learn the exam reference language, trace programs, and reason about selection and iteration.

6 lessons15 estimated blocksAP topics 3.1, 3.3–3.918 original exam questions

Unit overview

Use these lessons like the Algebra II and Physics pages: read the notes, learn the vocabulary, follow a worked example, attempt the quick checks before revealing solutions, and make a prediction before running the investigation.

15 blocks85-minute blocks, approximately 5–7 in the 16-week map
6 lessonsNotes, examples, vocabulary and quick checks
18 questionsFilterable exam-style bank

Success criteria

  • Translate between Python and AP pseudocode.
  • Evaluate AND, OR and NOT accurately.
  • Trace IF / ELSE IF / ELSE branching.
  • Trace counted and condition-controlled loops.
  • Create trace tables for multi-step programs.
  • Explain an algorithm in natural language.
Course model: CodeHS for targeted coding, this page for conceptual understanding, and AP Classroom for official aligned assessment. This is an original supplementary resource, not an official College Board publication.

Lesson map

Lesson numbering on this page is site-specific. CodeHS uses a different lesson numbering system.

Site lessonOfficial AP topicsSelected CodeHS lessons
3.1 AP reference language and assignment3.1, 3.3–3.53.4 Variables; 3.6 Basic Math in Python
3.2 Boolean expressions3.5–3.64.1 Booleans; 4.2 Logical Operators; 4.3 Comparison Operators
3.3 Selection and nested conditionals3.64.4 If Statements; 1.11 If Statements; 1.12 If/Else Statements
3.4 Iteration: REPEAT and REPEAT UNTIL3.84.6 For Loops in Python; 4.10 While Loops; 1.13 While Loops in Karel
3.5 Trace tables and nested structures3.5–3.94.7 General For Loops; 4.8 For Loop Practice; 4.11 Loop and a Half
3.6 Testing and algorithm comparison3.7–3.94.12 Python Control Structures Quiz; 1.15 Debugging Strategies

Content notes, vocabulary & worked examples

Each lesson ends with two quick checks. Open each answer only after attempting the problem.

Lesson 3.1 · AP 3.1, 3.3–3.5 · 1–2 blocks

AP reference language and assignment

CodeHS: 3.4 Variables; 3.6 Basic Math in Python

Learning targets

  • Translate between Python and AP pseudocode.
  • Trace assignment and arithmetic updates.

Core notes

AP pseudocode uses ← for assignment and DISPLAY for output. Evaluation occurs before assignment: x ← x + 1 is meaningful. DIV and MOD represent integer quotient and remainder. Parentheses determine grouping. Refer to the official AP reference sheet rather than assuming Python syntax or behaviors.

Vocabulary

assignment
store evaluated value
variable
named stored value
MOD
remainder operation
DISPLAY
output instruction

Worked example

x ← 5; y ← x MOD 2; x ← x + y; DISPLAY(x) gives 6.

Try it · Check your understanding

1. What does x ← x + 3 do?
Show solution
It evaluates the old value of x plus three, then stores the result in x.
2. Evaluate 17 MOD 5.
Show solution
2 because 17 = 3×5 + 2.
Lesson 3.2 · AP 3.5–3.6 · 1–2 blocks

Boolean expressions

CodeHS: 4.1 Booleans; 4.2 Logical Operators; 4.3 Comparison Operators

Learning targets

  • Evaluate AND, OR and NOT accurately.
  • Construct truth tables for compound conditions.

Core notes

Boolean values are true or false. AND requires both operands true; OR requires at least one; NOT negates a value. Use parentheses to avoid precedence confusion. A condition can be logically valid even if it is never satisfied for a particular set of inputs.

Vocabulary

Boolean
true/false value
AND
both conditions true
OR
at least one condition true
NOT
negation
comparison
tests relation between values

Worked example

For x=7, (x>5) AND (x<10) is true; (x<3) OR (x=7) is also true.

Try it · Check your understanding

1. Is NOT (true AND false) true or false?
Show solution
True: true AND false is false, then NOT makes it true.
2. Is (x<0) AND (x>10) possible for an ordinary number?
Show solution
No; both conditions cannot hold simultaneously.
Lesson 3.3 · AP 3.6 · 1–2 blocks

Selection and nested conditionals

CodeHS: 4.4 If Statements; 1.11 If Statements; 1.12 If/Else Statements

Learning targets

  • Trace IF / ELSE IF / ELSE branching.
  • Choose boundary tests for decision logic.

Core notes

A conditional executes only the branch whose test is satisfied. Ordering matters: the first satisfied branch in an IF/ELSE IF chain wins. Nested decisions are evaluated only when their enclosing branch is entered. >= versus > is a common boundary error.

Vocabulary

selection
conditional branch
branch
path through a program
boundary case
input at decision cutoff

Worked example

IF score≥90: A; ELSE IF score≥80: B; ELSE: C. Score 80 produces B and 90 produces A.

Try it · Check your understanding

1. Which grade appears for score 79?
Show solution
C, because neither preceding condition is true.
2. Why test score 90 and 89?
Show solution
They straddle the cutoff and can expose > versus ≥ mistakes.
Lesson 3.4 · AP 3.8 · 1–2 blocks

Iteration: REPEAT and REPEAT UNTIL

CodeHS: 4.6 For Loops in Python; 4.10 While Loops; 1.13 While Loops in Karel

Learning targets

  • Trace counted and condition-controlled loops.
  • Detect nontermination and off-by-one errors.

Core notes

Iteration repeats a block of statements. REPEAT n TIMES runs a block n times. REPEAT UNTIL(condition) continues until its condition becomes true (the AP reference specifies its exact behavior). Always record variable changes after each iteration. An unchanged loop variable may prevent termination.

Vocabulary

iteration
repeating instructions
loop guard
condition controlling repetition
off-by-one
one too many/few iterations
termination
eventual stop

Worked example

x ← 0; REPEAT 4 TIMES { x ← x + 2 }; DISPLAY(x) gives 8.

Try it · Check your understanding

1. How many additions does REPEAT 5 TIMES perform?
Show solution
Five if the addition occurs once within its repeated block.
2. Why can a loop run forever?
Show solution
Its stopping condition may never become true.
Lesson 3.5 · AP 3.5–3.9 · 1–2 blocks

Trace tables and nested structures

CodeHS: 4.7 General For Loops; 4.8 For Loop Practice; 4.11 Loop and a Half

Learning targets

  • Create trace tables for multi-step programs.
  • Differentiate final state from intermediate output.

Core notes

Use one row per executed operation or iteration, not just one row per line of source code. Track multiple variables and any DISPLAY statement. Nested loops multiply executions; if an outer loop runs 3 times and its inner loop runs 4 times each time, the inner body executes 12 times.

Vocabulary

trace table
record of state changes
state
current stored values
nested loop
loop inside another loop

Worked example

total ← 0; REPEAT 3 TIMES { REPEAT 2 TIMES { total ← total+1 } }; total becomes 6.

Try it · Check your understanding

1. How many times does the inner block run for 4 outer and 3 inner repeats?
Show solution
12 times.
2. Why is recording only the final sum insufficient?
Show solution
It conceals when variables changed and makes debugging harder.
Lesson 3.6 · AP 3.7–3.9 · 1–2 blocks

Testing and algorithm comparison

CodeHS: 4.12 Python Control Structures Quiz; 1.15 Debugging Strategies

Learning targets

  • Explain an algorithm in natural language.
  • Choose inputs that expose specific incorrect behavior.

Core notes

A correct output on one input does not prove an algorithm correct for all inputs. Compare two algorithms using counterexamples. Design tests for zero, first/last values, branches, boundaries, and termination. Evaluate correctness before speed.

Vocabulary

counterexample
input disproving claim
test case
chosen input and expected result
correctness
behavior matches specification

Worked example

To test an algorithm claiming to identify even numbers, use 0, 1, 2, -2, and an odd negative number if negatives are permitted.

Try it · Check your understanding

1. Can one successful test prove program correctness?
Show solution
No; other inputs may reveal failures.
2. Why compare outputs of algorithms on boundary inputs?
Show solution
Small differences often emerge at branch or loop boundaries.

Lesson videos & resources

Core video selection: The matching CodeHS lesson video and AP Daily topic video for each lesson. Direct AP Daily videos are accessed inside the school's AP Classroom enrollment and may not have public URLs.

  1. Lesson 3.1: AP reference language and assignment. Watch the matched CodeHS lesson video and the corresponding AP Daily topic video for 3.1, 3.3–3.5; pause to answer the notes prompt before the interactive lab. AP Daily requires student login.
  2. Lesson 3.2: Boolean expressions. Watch the matched CodeHS lesson video and the corresponding AP Daily topic video for 3.5–3.6; pause to answer the notes prompt before the interactive lab. AP Daily requires student login.
  3. Lesson 3.3: Selection and nested conditionals. Watch the matched CodeHS lesson video and the corresponding AP Daily topic video for 3.6; pause to answer the notes prompt before the interactive lab. AP Daily requires student login.
  4. Lesson 3.4: Iteration: REPEAT and REPEAT UNTIL. Watch the matched CodeHS lesson video and the corresponding AP Daily topic video for 3.8; pause to answer the notes prompt before the interactive lab. AP Daily requires student login.
  5. Lesson 3.5: Trace tables and nested structures. Watch the matched CodeHS lesson video and the corresponding AP Daily topic video for 3.5–3.9; pause to answer the notes prompt before the interactive lab. AP Daily requires student login.
  6. Lesson 3.6: Testing and algorithm comparison. Watch the matched CodeHS lesson video and the corresponding AP Daily topic video for 3.7–3.9; pause to answer the notes prompt before the interactive lab. AP Daily requires student login.

Additional concept resources

Video selections are topic- and platform-matched. Teachers should check account availability and assign individual CodeHS/AP Daily clips from their course dashboards.

Interactive inquiry · Pseudocode stepper & Boolean lab

Make a prediction, manipulate the model, record observations, and explain whether your original thinking was correct.

Student lab record: Before you start, write your prediction and reasoning. Afterward, record at least two trials and an evidence-based conclusion. This model is illustrative and its limitations should be noted.

Investigation A · Pseudocode execution

Predict the final output before stepping. This sample uses official-style assignment, REPEAT and DISPLAY notation.

total ← 1
REPEAT 4 TIMES {
    total ← total * 2
}
DISPLAY(total)
Completed iterations
0
Current total
1
Displayed output
—

Initialization complete. Predict before stepping.

Investigation B · Boolean logic table

Choose a logical operator. Verify all four possible combinations of two Boolean values.

Investigation record

Lab responses stay in this page; they are not uploaded or stored on a server.

AP-style practice & self-check

Original multiple-choice questions focus on reasoning, not just coding. Filter by lesson and difficulty. Show explanations in practice mode or hide them in exam mode.

Mastery target: 80% on mixed original questions, plus a clear written explanation on one unfamiliar scenario. Treat the bank as practice, not a secure test.

Teacher lesson specifications & implementation

Teacher-facing scope, exact learning goals, CodeHS alignments, and assessment requirements. This section can be hidden or separated before student publishing.

Pacing and lesson allocation

15 × 85-minute blocks. Shorten or extend CodeHS programming time based on prior experience and how many blocks actually meet; all lessons are supplemental to the main CodeHS course.

Default block: 10 min retrieval · 20 min notes/video · 20 min inquiry · 25 min selected CodeHS/independent practice · 10 min quick assessment.

LessonAPCodeHSMeasurable targetsAssessment specifications
3.1 AP reference language and assignment3.1, 3.3–3.53.4 Variables; 3.6 Basic Math in PythonTranslate between Python and AP pseudocode.; Trace assignment and arithmetic updates.2 quick checks + 3 exam-bank items; lab discussion / exit ticket
3.2 Boolean expressions3.5–3.64.1 Booleans; 4.2 Logical Operators; 4.3 Comparison OperatorsEvaluate AND, OR and NOT accurately.; Construct truth tables for compound conditions.2 quick checks + 3 exam-bank items; lab discussion / exit ticket
3.3 Selection and nested conditionals3.64.4 If Statements; 1.11 If Statements; 1.12 If/Else StatementsTrace IF / ELSE IF / ELSE branching.; Choose boundary tests for decision logic.2 quick checks + 3 exam-bank items; lab discussion / exit ticket
3.4 Iteration: REPEAT and REPEAT UNTIL3.84.6 For Loops in Python; 4.10 While Loops; 1.13 While Loops in KarelTrace counted and condition-controlled loops.; Detect nontermination and off-by-one errors.2 quick checks + 3 exam-bank items; lab discussion / exit ticket
3.5 Trace tables and nested structures3.5–3.94.7 General For Loops; 4.8 For Loop Practice; 4.11 Loop and a HalfCreate trace tables for multi-step programs.; Differentiate final state from intermediate output.2 quick checks + 3 exam-bank items; lab discussion / exit ticket
3.6 Testing and algorithm comparison3.7–3.94.12 Python Control Structures Quiz; 1.15 Debugging StrategiesExplain an algorithm in natural language.; Choose inputs that expose specific incorrect behavior.2 quick checks + 3 exam-bank items; lab discussion / exit ticket

Summative assessment blueprint

40 points: 20 original AP-style multiple-choice questions (1 point each), four short-answer reasoning prompts (3 points each), and one 8-point novel investigation/analysis. Mix current-unit and prior-unit topics. Use AP Classroom separately for official question practice.

Assessment and feedback strategy

  • Independent predictions precede each simulation.
  • Students justify one wrong multiple-choice distractor in writing.
  • Teacher verifies model limitations, not just numeric answers.
  • Repeat key pseudocode and binary ideas in later units.

Source and alignment notes

Continue through the course