Back to Review Hub

Reading Pseudocode

The AP Computer Science Principles Reference Sheet, decoded · ~30–45 min

What This Lesson Covers

The AP CSP exam uses its own language-agnostic pseudocode — not Python, not Java. The good news: you get the full reference sheet on the exam. You don't have to memorize syntax. You just have to read it confidently.

This lesson is a fast tour of every section of the reference sheet, with the gotchas that trip up most students.

1. The AP Reference SheetProvided on the exam

The College Board provides a Reference Sheet at the start of the exam booklet. It explains every pseudocode instruction you might see. It is not a list of code to memorize — it is your dictionary while answering questions.

Strategy: When you see a programming question, flip back to the reference sheet for any operator or instruction you're not 100% sure about. Use it. Don't try to remember exactly what REPEAT UNTIL does — look it up.

The reference sheet has both a text format (what we'll use here) and a block format (drag-and-drop blocks like Scratch). Both formats show up on the exam. They mean the same thing — only the appearance differs.

Open the AP CSP Reference Sheet (PDF)

This is the exact reference sheet you'll have printed in your exam booklet. Open it in another tab and keep it handy as you work through this lesson.

2. Assignment vs. Equality

This is the #1 source of student confusion on AP CSP code questions:

SymbolWhat it meansExample
(left arrow) Assignment. Evaluate the right side, then store the result in the variable on the left. x ← 5 — puts the value 5 in x
= (equals sign) Equality test. Evaluates to true if the two sides are equal, false otherwise. x = 5 — is x equal to 5?
Remember: If you see an arrow , the variable on the left is being changed. If you see =, it's a yes/no question, not an action.

Other "actions": DISPLAY and INPUT

  • DISPLAY(expression) — prints the value, followed by a space.
  • INPUT() — pauses and returns whatever the user types.

3. Arithmetic Operators

Standard math: +, -, *, /. Normal order of operations. Plus two special ones:

OperatorMeaningExample
a MOD b The remainder when a is divided by b. Same precedence as * and /. 17 MOD 5 evaluates to 2 (because 17 = 3×5 + 2)
RANDOM(a, b) Returns a random integer from a to b, inclusive of both endpoints. Each value is equally likely. RANDOM(1, 3) could return 1, 2, or 3.
MOD is "remainder," not "divide." 17 / 5 evaluates to 3.4. 17 MOD 5 evaluates to 2. Big difference.

4. Comparison & Boolean Operators

Comparison (yes/no questions)

These all produce a Boolean (true or false):

OperatorMeaning
a = bEqual to
a ≠ bNot equal to
a > b / a < bGreater than / less than
a ≥ b / a ≤ bGreater-than-or-equal / less-than-or-equal

Boolean combinators

OperatorMeaning
NOT conditiontrue if condition is false; flips the value.
a AND btrue only when both are true.
a OR btrue when at least one is true (including both).
Translating English to Boolean: "between 50 and 80 inclusive" means (x ≥ 50) AND (x ≤ 80). Inclusive means use and ; exclusive means use > and <.
Practice MCQ · 2021 Exam Q2

To be eligible for a particular ride at an amusement park, a person must be at least 12 years old and must be between 50 and 80 inches tall, inclusive. Let age represent the person's age in years, and height the person's height in inches. Which expression evaluates to true if and only if the person is eligible for the ride?

5. Selection: IF and IF / ELSE

IF(condition)
{
    <block of statements>
}

Run the block only if the condition is true. Otherwise, skip it entirely.

IF(condition)
{
    <first block>
}
ELSE
{
    <second block>
}

Run the first block if the condition is true; otherwise run the second block. Exactly one of the two blocks runs.

Two separate IFs are not the same as IF / ELSE. Two separate IF blocks can both run, or both skip. An IF / ELSE always runs exactly one. This distinction is the bug in a classic AP exam question (Q34 below).
Practice MCQ · 2021 Exam Q34

Result X is expected to occur 25% of the time and result Y 75% of the time. The following code is intended to simulate 100 trials, but it counted only 94 trials (24 + 70). Which change fixes the bug?

Line 1: xCount ← 0
Line 2: yCount ← 0
Line 3: REPEAT 100 TIMES
Line 4: {
Line 5:     IF(RANDOM(1, 4) = 1)
Line 6:     {
Line 7:         xCount ← xCount + 1
Line 8:     }
Line 9:     IF(RANDOM(1, 4) > 1)
Line 10:    {
Line 11:        yCount ← yCount + 1
Line 12:    }
Line 13: }

6. Iteration: REPEAT and FOR EACH

LoopWhat it does
REPEAT n TIMES Runs the block exactly n times.
REPEAT UNTIL(condition) Keeps running the block until the condition becomes true. If the condition is already true at the start, the block doesn't run at all.
FOR EACH item IN aList Assigns each element of aList to the variable item, in order from first to last. The block runs once per element.
Gotcha: REPEAT UNTIL stops when the condition is true. Many students read it as "repeat while" and get the logic backwards. Until true.
FOR EACH gives you the value, not the index. If aList is [10, 20, 30], then FOR EACH item IN aList assigns item the values 10, 20, 30 — not 1, 2, 3.

7. Lists

The single biggest pseudocode trap on the AP exam: AP CSP lists are 1-indexed. The first element of a list is at index 1, not 0. This is the opposite of Python, JavaScript, Java, C, etc.

So for aList ← [10, 20, 30]:

  • aList[1] is 10 (first element)
  • aList[2] is 20
  • aList[3] is 30 (last element)
  • aList[0]error! the program terminates.

List operations

OperationWhat it does
aList ← [v1, v2, v3]Creates the list with those values at indices 1, 2, 3.
aList[i] ← xReplaces the value at index i with x.
APPEND(aList, value)Adds value to the end. List length grows by 1.
INSERT(aList, i, value)Shifts elements at i and beyond to the right, then places value at index i. Length grows by 1.
REMOVE(aList, i)Deletes the item at index i, shifts the rest left. Length shrinks by 1.
LENGTH(aList)Returns the number of elements in the list.
Useful pattern: aList[LENGTH(aList)] always gives the last element — because lists are 1-indexed, the last index equals the length.

8. Procedures and RETURN

PROCEDURE procName(parameter1, parameter2, ...)
{
    <block of statements>
    RETURN(expression)
}

A procedure is a named, reusable block of code that takes inputs (called parameters) and may return a result.

Calling a procedure

  • procName(arg1, arg2) — runs the procedure with those arguments.
  • result ← procName(arg1, arg2) — runs it and stores the returned value in result.
RETURN exits the procedure immediately. As soon as a RETURN statement runs, control goes back to whoever called the procedure. Anything after that RETURN in the same procedure won't execute.
Practice MCQ · 2021 Exam Q14

The procedure below is intended to return true if numberList is "increasing" (each value ≥ the one before) and false otherwise. It contains a bug. Which change is needed?

Line 1: PROCEDURE isIncreasing(numberList)
Line 2: {
Line 3:     count ← 2
Line 4:     REPEAT UNTIL(count > LENGTH(numberList))
Line 5:     {
Line 6:         IF(numberList[count] < numberList[count - 1])
Line 7:         {
Line 8:             RETURN(true)
Line 9:         }
Line 10:        count ← count + 1
Line 11:    }
Line 12:    RETURN(false)
Line 13: }

9. Robot Commands

Some exam questions use a small robot in a grid. The reference sheet defines four commands:

CommandWhat it does
MOVE_FORWARD()Moves the robot one square forward, in the direction it is currently facing.
ROTATE_LEFT()Turns the robot 90° counterclockwise in place. Does not move it.
ROTATE_RIGHT()Turns the robot 90° clockwise in place. Does not move it.
CAN_MOVE(direction)Returns true if the square in that direction is open and on the grid. direction can be forward, backward, left, or right.
Hidden trap: If the robot tries to move into a blocked square or off the grid, the robot stays put and the program terminates. Always check CAN_MOVE before MOVE_FORWARD if there's any chance of running into an edge.

10. How to Trace Code Like a Pro

"Trace tables" turn confusing code into a simple ledger. The trick: pick a fresh sheet of scratch paper, draw one column per variable, and write down every value as it changes.

Example trace

x ← 3
y ← 5
REPEAT 3 TIMES
{
    x ← x + y
    y ← y - 1
}
DISPLAY(x)
StepxyNotes
Start35Initial assignments
Loop 184x = 3+5, y = 5−1
Loop 2123x = 8+4, y = 4−1
Loop 3152x = 12+3, y = 3−1
Display15Final answer
Don't trace in your head. Every year, students miss tracing questions they could've gotten by writing two columns on paper. Use the scratch space in your test booklet.

Misconception Lightning Round

Click True or False:

"You have to memorize the reference sheet because it isn't given to you on the exam."

"In AP CSP pseudocode, the first element of a list is at index 0."

"The symbol = stores a value in a variable."

"REPEAT UNTIL(condition) keeps looping while the condition is true."

"17 MOD 5 evaluates to 3 or 3.4 (the quotient)."

"aList[LENGTH(aList)] always evaluates to the last element of the list."

What's NOT on the AP CSP Exam

Don't spend study time on these — they're real programming concepts but they're not tested:

  • Memorizing Python, Java, or JavaScript syntax Out of scope
  • Object-oriented programming, classes, inheritance Out of scope
  • Pointers, memory management, types beyond {number, Boolean, string, list} Out of scope
  • Recursion as a tested topic (it can show up incidentally, but is not on the framework) Out of scope
  • Specific sorting algorithm names (bubble sort, quicksort, etc.) Out of scope
  • Big-O notation specifics — you only need "reasonable time" vs. "not reasonable time" Out of scope

Translation: The exam is testing whether you can read code, not whether you can write a specific language. Reference sheet + tracing skill = most pseudocode questions.

More Info — Trusted Sources to Verify or Go Deeper

Everything on this page is drawn directly from the College Board's official AP CSP Reference Sheet (the same one printed inside the exam booklet) and the 2021 released practice exam. If you want to see the original document or read deeper, these are the references your teachers and the College Board treat as authoritative.

Back to Review Hub