AP Computer Science Principles

Read It. Understand It.
Solve It with Pseudocode.

A complete guide to AP CSP's official pseudocode — from decoding symbols to writing logic. Master the reference sheet, then prove it with an interactive fill-in-the-blank challenge.

Presentation Talking Points
  • What is pseudocode? — It's a plain-English-like way to describe algorithms without worrying about syntax errors. AP CSP uses its own standardized version.
  • Why does it matter on the exam? — Every MCQ algorithm question and the Create Task rubric uses this exact notation. Reading it fluently is a tested skill.
  • Assignment () is not equality — It means "evaluate the right side and store the result in the variable on the left." A common trap question.
  • The three pillars of all programs: Sequence (order matters), Selection (IF/ELSE decisions), Iteration (REPEAT loops).
  • Lists start at index 1 — Unlike Python or JavaScript. Out-of-bounds access terminates the program — watch for that in tricky MCQs.
  • MOD is remainder, not division — 17 MOD 5 = 2. Classic use: check if a number is even with n MOD 2 = 0.
  • REPEAT UNTIL stops when the condition becomes true — The opposite of a while-loop mental model. Easy to misread under pressure.
  • Procedures can RETURN values — The return value can be stored in a variable. A procedure without RETURN is like a void function.
  • How to read any pseudocode problem: (1) Find the variables, (2) Trace the loop, (3) Check the condition, (4) Track what gets returned or displayed.
  • The drag-and-drop game at the end uses real exam-style problems. Each blank tests one concept — try to predict the answer before dragging.

What Is Pseudocode?

Pseudocode is a human-readable description of an algorithm — it looks like code, but it's designed to communicate logic, not run on a machine. AP CSP uses a standardized pseudocode that appears on your exam reference sheet. Every question involving algorithms, programs, and robots uses this exact notation, so learning to read it fluently is one of the highest-leverage skills you can build before exam day.

Think of it as a bridge: it's more precise than plain English, but less picky than real code. You'll never get a syntax error for a missing semicolon — but you will get a wrong answer if you misread a as an =.

Key Terms Glossary

Every term below appears directly in AP CSP exam problems. Hover over a card to highlight it.

Algorithm
A finite, step-by-step set of instructions that solves a problem or accomplishes a task. Every program is an algorithm.
Variable
A named storage location that holds a value. The value can be read or overwritten at any point in the program.
score ← 0
Assignment ( ← )
Evaluates the expression on the right and stores a copy of the result into the variable on the left. It is NOT a test for equality.
x ← x + 1
Sequence
Instructions that execute one after another, in top-to-bottom order. The foundation of all programs.
Selection
A decision point in the program. Uses IF or IF/ELSE to choose which block of code runs based on a Boolean condition.
IF (x > 0) { ... }
Iteration
Repeating a block of code. AP CSP has two forms: REPEAT n TIMES (fixed count) and REPEAT UNTIL (condition-based).
REPEAT 5 TIMES { ... }
Boolean
A value that is either true or false. All conditions in IF and REPEAT UNTIL evaluate to a Boolean.
a > b → true or false
MOD (Remainder)
Returns the remainder after integer division. Same precedence as * and /. Commonly used to check even/odd or wrap around.
17 MOD 5 → 2
List
An ordered collection of values accessed by index. AP CSP lists start at index 1 — not 0. Going out of bounds terminates the program.
aList[1] ← first item
Procedure
A named, reusable block of code. It can accept parameters (inputs) and optionally RETURN a value. Reduces repetition through abstraction.
PROCEDURE add(a, b) { ... }
Parameter
A variable inside a procedure definition that receives the value of an argument when the procedure is called.
procName(param1, param2)
RETURN
Immediately exits the procedure and sends back a value to the caller. Execution of the procedure stops at RETURN.
RETURN(result)

Step-by-Step: How to Read Any Pseudocode Problem

When you encounter pseudocode on the exam, follow these steps in order. Don't jump ahead — trace the code like the computer would.

1
Identify all variables and their starting values
Find every statement above the main logic. Write each variable name and its initial value on scratch paper. You can't trace a program you haven't initialized.
2
Read top to bottom — sequence matters
AP CSP pseudocode executes line by line, top to bottom, unless a loop or conditional changes the flow. Never assume two lines run at the same time.
3
Evaluate conditions as true or false — never skip them
When you hit an IF or REPEAT UNTIL, substitute real values into the condition and decide: true or false? Only then decide which branch executes or whether the loop continues.
4
Trace loops iteration by iteration
For every loop iteration, update all variables and re-check the condition. Keep a table: one column per variable, one row per iteration. This prevents the most common tracing mistakes.
5
Track what gets DISPLAYED or RETURNED
The exam question usually asks what the program outputs or returns. Circle every DISPLAY and RETURN as you trace so you don't miss any output.
6
Watch the index when using lists
AP CSP lists start at index 1. If a loop runs from 1 to LENGTH(aList), that's correct. If it tries to access index 0 or index LENGTH+1, the program terminates with an error.

Pseudocode Concepts in Detail

Assignment & Display

What it looks like
score 0 score score + 10 DISPLAY(score)
What happens
Line 1: score is created and set to 0.
Line 2: The right side (score + 10 = 10) is computed first, then stored back into score. Variable is now 10.
Line 3: Outputs 10 followed by a space.

Selection — IF / ELSE

What it looks like
IF (grade 90) { DISPLAY("A") } ELSE { DISPLAY("Not an A") }
What happens
The condition grade ≥ 90 is tested. If true, only the first block runs. If false, only the ELSE block runs. Exactly one branch always executes.

Exam trap: An IF without ELSE does nothing when the condition is false — it doesn't crash.

Iteration — REPEAT

Two forms
-- Runs exactly 3 times -- REPEAT 3 TIMES { DISPLAY("hello") } -- Runs UNTIL count hits 0 -- count 3 REPEAT UNTIL (count = 0) { DISPLAY(count) count count - 1 }
Key distinction
REPEAT n TIMES — runs the block exactly n times. No condition to evaluate.

REPEAT UNTIL(condition) — checks the condition before each iteration. Stops when the condition becomes true.

Common mistake: Students confuse this with "repeat WHILE false." Remember: it stops when the condition is true, not while it's false.

Lists & FOR EACH

What it looks like
nums [10, 20, 30] total 0 FOR EACH item IN nums { total total + item } DISPLAY(total) -- Displays 60 --
List rules to memorize
• Lists start at index 1, not 0.
aList[1] is the first element.
LENGTH(aList) returns the count.
APPEND(aList, val) adds to the end.
INSERT(aList, i, val) shifts items right.
REMOVE(aList, i) shifts items left.

FOR EACH visits every element in order — you don't need to manage an index variable.

Procedures

What it looks like
PROCEDURE isEven(n) { IF (n MOD 2 = 0) { RETURN(true) } ELSE { RETURN(false) } } result isEven(4) -- result is true --
How it works
1. isEven(4) is called — the value 4 is copied into parameter n.
2. 4 MOD 2 = 0true.
3. RETURN(true) immediately exits the procedure.
4. The returned value true is stored in result.

No RETURN? The procedure runs its block and exits without sending back a value — like a void function.

Interactive Challenge
Drag-and-Drop Code Bank

Each challenge below has a missing code block marked with a drop zone. Drag the correct token from the code bank into the blank. Read the objectives first — they tell you exactly what the code should do.

Solved: 0 / 4
Attempts: 0
1
Sum of a List
Objectives
  • Start with a running total of 0
  • Visit each number in numList one at a time
  • Add each number to the running total
  • Display the final sum after the loop ends
total 0 FOR EACH num IN numList { total total + drag here } DISPLAY(total)
Code Bank
numList
num
total
0
2
Find the Maximum
Objectives
  • Assume the first element is the largest to start
  • Visit every element in aList using FOR EACH
  • If the current element is greater than the current max, update max
  • Return the maximum value found
PROCEDURE findMax(aList) { max aList[1] FOR EACH item IN aList { IF (drag here > max) { max item } } RETURN(max) }
Code Bank
max
aList
item
LENGTH
3
Even Number Check
Objectives
  • Accept a number n as a parameter
  • Use the MOD operator to test divisibility
  • A number is even when dividing by this value leaves remainder 0
  • Return true if even, false otherwise
PROCEDURE isEven(n) { IF (n MOD drag here = 0) { RETURN(true) } ELSE { RETURN(false) } }
Code Bank
n
0
2
1
4
Countdown Loop
Objectives
  • Start a counter at 5
  • Display the counter value each iteration
  • Decrease the counter by 1 each time
  • Stop the loop when this variable reaches 0
count 5 REPEAT UNTIL (drag here = 0) { DISPLAY(count) count count - 1 }
Code Bank
5
0
count
1
All Challenges Complete!

You filled in all four blanks correctly. You can read AP CSP pseudocode.