AP CSP pseudocode, runnable
The exact language from the AP Computer Science Principles exam — type it, run it, and step through it with a variable table and the robot on a grid. Real exam semantics: lists start at 1, division is real division, and a robot that hits a wall terminates the program. The full reference sheet below is clickable: every construct loads as a runnable example.
INPUT() values — one per line
Robot world
Variables
Output
Every construct, runnable
The exam gives you a reference sheet describing this language — the students who recognize each line instantly spend their time thinking, not decoding. Click any row to load a working example into the interpreter above.
Assignment, display, input
DISPLAY prints the value followed by a single space — that is why exam output reads like one long line.
Arithmetic and random
Division is REAL division — the number-one difference from Java and Python habits.
Comparison and logic
Selection
Iteration
REPEAT UNTIL checks BEFORE each pass and loops while the condition is false — if it starts true, the body never runs.
Lists — indexes start at 1
aList[1] is the FIRST element and aList[LENGTH(aList)] is the last. Index 0 is an error here, exactly like on the exam.
Procedures
Robot
The robot lives on a grid of squares and faces a direction. The exam rule: an impossible MOVE_FORWARD terminates the program — so test with CAN_MOVE first.
AP CSP pseudocode questions
What is AP CSP pseudocode?
It is the small language the AP Computer Science Principles exam uses in multiple-choice questions: arrow assignment, DISPLAY, IF/ELSE, REPEAT n TIMES, REPEAT UNTIL, FOR EACH, lists, procedures with RETURN, and a robot on a grid. The exam hands you a reference sheet describing it — recognizing every construct instantly is free points, and this page lets you run each one.
Are AP CSP lists 0-indexed or 1-indexed?
1-indexed: the first element of aList is aList[1], and the last is aList[LENGTH(aList)]. This is the single most common trap for students coming from Python or Java, and this interpreter enforces it — index 0 is an error, just like on the exam.
Is division in AP CSP pseudocode integer division?
No. The / operator is real division: 7 / 2 evaluates to 3.5, unlike int division in Java or // in Python. For remainders the language uses MOD: 7 MOD 2 is 1.
How does REPEAT UNTIL work?
REPEAT UNTIL(condition) checks the condition BEFORE every iteration and runs the block while the condition is false. If the condition is already true at the start, the block never runs — a favorite exam question.
What happens when the robot hits a wall?
If MOVE_FORWARD would take the robot into a blocked square or off the grid, the robot stays put and the program terminates — that is the official exam rule, and this interpreter stops with the same error. Use CAN_MOVE(forward), CAN_MOVE(left), CAN_MOVE(right) or CAN_MOVE(backward) to test before moving.
Is this AP CSP pseudocode interpreter free?
Yes. It runs entirely in your browser with no account, works on Chromebooks, and is part of Silver, the free AP Computer Science practice platform.