AP CSP Ap Pseudocode Syntax

AP CSP Topics › AP Pseudocode Syntax

AP CSP Pseudocode Syntax: Complete Guide (2025‑2026)

AP pseudocode is College Board’s custom language used exclusively on the AP CSP exam. It is not Java, Python, or any real language. Key differences: assignment uses not =, list indexing starts at 1 not 0, = means comparison not assignment in conditions, and loops use REPEAT/FOR EACH not for/while. Mixing Java or Python habits into AP pseudocode answers costs points.

Assignment operator in AP pseudocode — never = for assignment
1List index of the first element — not 0
=Comparison operator in AP pseudocode conditions — not ==

Quick Reference Card

AP Pseudocode vs. Common Languages: Key Differences AP Pseudocode x ← 5 IF x > 3 REPEAT 4 TIMES FOR EACH n IN list list[1] x = 5 (comparison) RETURN val Java x = 5; if (x > 3) for(int i=0;i<4;i++) for(int n : list) list[0] x == 5 (comparison) return val; Python x = 5 if x > 3: for i in range(4): for n in list: list[0] x == 5 (comparison) return val

AP pseudocode has unique syntax that differs from both Java and Python. Never bring language-specific habits onto the AP exam.

Complete AP Pseudocode Syntax Reference
-- ASSIGNMENT -- x 5 # stores 5 in x -- DISPLAY -- DISPLAY(x) # outputs value of x -- SELECTION -- IF condition # body ELSE IF condition2 # body ELSE # body -- ITERATION -- REPEAT n TIMES # body runs exactly n times REPEAT UNTIL condition # body runs until condition is TRUE FOR EACH item IN list # body runs once per element -- PROCEDURES -- PROCEDURE name(param1, param2) RETURN value -- LIST OPERATIONS -- APPEND(list, val) INSERT(list, i, val) REMOVE(list, i) LENGTH(list) -- OPERATORS -- # Arithmetic: + - * / MOD # Comparison: = ≠ > < ≥ ≤ (= means equality, NOT assignment) # Logical: AND OR NOT

Critical Syntax Differences

Correct AP Pseudocode
Use exactly these forms on the exam
  • x ← 5 for assignment
  • IF x = 5 for comparison (= not ==)
  • list[1] for first element
  • REPEAT UNTIL x > 10 exits when TRUE
  • x MOD y for remainder (not %)
Common Wrong Syntax
Avoid these Java/Python habits
  • x = 5 for assignment (Java/Python style)
  • IF x == 5 (Java comparison, not AP)
  • list[0] for first element (0-indexed)
  • while x <= 10: (Python syntax)
  • x % y for remainder (Java/Python)

Code Trace Gauntlet

Trace 1 — Read the Syntax Carefully
a 3 b 4 IF a * b > 10 DISPLAY(“yes”) ELSE DISPLAY(“no”)

What displays?

Output

yes a*b=12. 12>10 is TRUE. IF block runs, displays yes.

Trace 2 — MOD Operator
DISPLAY(17 MOD 5) DISPLAY(10 MOD 3) DISPLAY(8 MOD 2)

What are the three outputs?

Output

2 1 0 17 MOD 5 = 2 (17 = 3*5+2). 10 MOD 3 = 1 (10 = 3*3+1). 8 MOD 2 = 0 (evenly divisible).

Trace 3 — Comparison vs Assignment
x 5 # assignment: x now holds 5 IF x = 5 # comparison: is x equal to 5? DISPLAY(“equal”) ELSE DISPLAY(“not equal”)

What displays? Notice = is used for both assignment and comparison.

Output

equal Line 1: ← is assignment. Line 2: = inside IF is comparison. x=5 is TRUE. Displays equal.

Trace 4 — Nested Procedures and Lists
PROCEDURE firstLast(lst) RETURN lst[1] + lst[LENGTH(lst)] nums [3,7,2,9] DISPLAY(firstLast(nums))

What does firstLast return?

Output

12 lst[1]=3 (first), lst[LENGTH(lst)]=lst[4]=9 (last). 3+9=12.

Spot the Bug

SPOT THE BUG — Java-Style Assignment
count = 0 REPEAT 5 TIMES count = count + 1
Bug Explained

Uses = for assignment instead of ←. In AP pseudocode, = inside an IF condition means comparison; ← is always assignment. Fix: count ← 0 and count ← count + 1.

SPOT THE BUG — Zero-Based Index in AP Pseudocode
scores [90,85,78] DISPLAY(scores[0])
Bug Explained

AP lists are 1-indexed. scores[0] is an error. Fix: scores[1] returns 90.

Common Exam Pitfalls

1
Using = for assignment instead of ←

The AP exam uses ← for assignment. = appears only in conditions (as equality comparison). Never write x = 5 as an assignment statement.

2
Using == for comparison (Java habit)

In AP pseudocode, = (single equals) is the comparison operator inside IF conditions. Java’s == and Python’s == are not used.

3
Zero-based list indexing

AP lists start at 1. list[1] is the first element. Do not apply Python or Java 0-based habits.

4
Using % instead of MOD for remainder

AP pseudocode uses the keyword MOD. 10 MOD 3 = 1. Writing 10 % 3 uses Java/Python syntax and is wrong on the AP exam.

Check for Understanding

1. In AP pseudocode, which correctly assigns the value 7 to variable n?

  • n = 7
  • n ← 7
  • n == 7
  • n := 7
AP pseudocode uses ← for assignment.

2. In AP pseudocode, which correctly tests whether x equals 10 inside an IF condition?

  • IF x ← 10
  • IF x == 10
  • IF x = 10
  • IF x.equals(10)
In AP pseudocode conditions, = is the equality comparison operator.

3. DISPLAY(15 MOD 4) outputs:

  • 3
  • 4
  • 3.75
  • 0
15 = 3*4+3. 15 MOD 4 = 3.

4. lst ← [10,20,30]
DISPLAY(lst[1])
outputs:

  • 0 — first index is 0
  • 10 — first index is 1 in AP pseudocode
  • 20
  • Error
AP lists are 1-indexed. lst[1]=10.

5. Which statement about AP pseudocode syntax is correct?

  • REPEAT UNTIL loops exit when the condition is FALSE
  • FOR EACH provides an index variable like a Java for loop
  • All list operations (APPEND, INSERT, REMOVE) modify the list in place
  • Procedures must always include a RETURN statement
APPEND, INSERT, REMOVE all modify the list directly. REPEAT UNTIL exits when TRUE (not FALSE). FOR EACH does not provide an index. RETURN is optional.

6. Which AP pseudocode expression correctly checks if n is odd?

  • n MOD 2 = 1
  • n % 2 == 1
  • n MOD 2 != 0
  • n / 2 = 1
n MOD 2 = 1 uses correct AP pseudocode: MOD for remainder, = for comparison.

7. Consider: I. ← is used for assignment in AP pseudocode. II. = inside an IF condition tests for equality. III. AP list indices start at 0. Which are correct?

  • I only
  • I and II only
  • I, II, and III
  • III only
I and II are correct. III is false — AP lists start at index 1.

8. x ← 10
IF x MOD 3 = 1
DISPLAY("yes")
ELSE
DISPLAY("no")

  • yes
  • no
  • 1
  • Error
10 MOD 3 = 1 (10=3*3+1). 1=1 is TRUE. Displays yes.

9. What does DISPLAY(LENGTH([5,10,15,20])) output?

  • 3
  • 4
  • 20
  • 5
LENGTH counts elements. 4 elements = LENGTH 4.

10. A student writes REPEAT UNTIL count < 10 with count starting at 1. How many times does the body run?

  • 0 — condition already true, REPEAT UNTIL skips
  • 1 — body runs once then condition checked and found TRUE
  • 9 — runs until count reaches 9
  • 10 — runs until count reaches 10
Body executes FIRST (post-check). After first run, check count<10: 1<10 TRUE → exits. Body ran once.

How the AP Exam Tests This

  • Read a code segment and identify what is displayed or what value a variable holds
  • Identify syntax errors (wrong operator, wrong index base, wrong loop keyword)
  • Evaluate a MOD expression with specific values
  • Determine whether AP pseudocode or Java/Python syntax is used correctly
  • I/II/III: identify which statements about AP pseudocode syntax are correct

FAQ

Does the AP exam give a reference sheet for pseudocode syntax?
Yes. The AP CSP exam provides a reference sheet with AP pseudocode syntax. However, exam questions require fluency with the syntax, not just the ability to look it up. Practicing with the pseudocode until it feels natural is essential.
What does ≠ mean in AP pseudocode?
≠ means not equal. It is the AP pseudocode inequality comparison operator. a ≠ b is TRUE when a and b have different values.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]