Mastering the AP CSP Exam Reference Sheet Notation
Welcome to one of the most reassuring parts of AP Computer Science Principles! Because high schools teach AP CSP using a wide variety of programming languages—such as Python, JavaScript, Java, or Scratch—the AP Exam does not test you on any single proprietary language. Instead, the College Board uses a universal language documented on the official AP CSP Exam Reference Sheet.
Every coding question on the exam is presented using this reference notation, provided in both text-based pseudocode and block-based visual layouts. Once you understand the specific conventions and rules of the Reference Sheet, you will be able to read, trace, and solve any question on the exam with complete confidence.
Note: For dedicated practice on underlying computational logic, see our companion chapters on "Variables and Assignments", "Mathematical Expressions", "Strings", "Boolean Expressions", "Conditionals", and "Data Abstraction".
Text vs. Block: Two Formats, One Meaning
On Section I of your exam (which includes \(70\) multiple-choice questions), code segments may appear as standard text pseudocode, as block diagrams, or even side-by-side. Both representations share the exact same logic and execution rules:
Text format: Uses written keywords and curly braces { } to group statements into blocks.
Block format: Encapsulates commands inside interlocking rectangular shapes, where the nested structure of loops and conditions is visually indented inside the block container.
Key Takeaway: Never worry about memorizing strange language-specific syntax like semicolons or indentation tabs. The Reference Sheet is provided to you on exam day, and both text and block formats follow identical logical rules.
1. Assignment, Input, and Display
Every program needs a way to store data, take input, and present results. The AP Reference Sheet defines three fundamental constructs for these tasks:
Assignment Operator: a <- expression
The AP Exam uses a left-pointing arrow (<-) to assign a value. In block format, this is represented as an arrow pointing to the target variable inside a block. The expression on the right is evaluated first, and a copy of the resulting value is stored in the variable on the left.
Display Statement: DISPLAY(expression)
This statement evaluates expression and displays its value. Crucial Exam Rule: The Reference Sheet explicitly states that DISPLAY prints the value followed by a space. For example, executing DISPLAY(\(1\)) followed immediately by DISPLAY(\(2\)) outputs \(1\text{ }2\text{ }\), not \(12\).
Input Statement: INPUT()
This construct accepts a value directly from the user and returns the input value to the program.
Common Mistake to Avoid: Confusing the assignment operator with equality. In text notation, a <- b means "put the value of \(b\) into variable \(a\)". It is not testing whether \(a\) equals \(b\)!
2. Arithmetic Operators and Numeric Procedures
The Reference Sheet defines standard arithmetic operators and special numeric procedures. Order of operations (PEMDAS) applies normally:
Basic Operators: +, -, *, and / represent addition, subtraction, multiplication, and division.
Division Warning: Division on the AP CSP exam is not integer division. Fractions and decimals are preserved. For instance, the expression \(17 / 5\) evaluates to \(3.4\).
The Modulo Operator: a MOD b
The MOD operator evaluates to the remainder when integer \(a\) (where \(a \ge 0\)) is divided by integer \(b\) (where \(b > 0\)). It holds the same mathematical precedence as multiplication (*) and division (/).
Example: \(17 \text{ MOD } 5\) evaluates to \(2\), because \(5\) goes into \(17\) three whole times with a remainder of \(2\).
Random Number Generation: RANDOM(a, b)
This procedure returns a randomly selected integer from \(a\) to \(b\), inclusive. Each integer in the range has an equal probability of being chosen.
Example: RANDOM(\(1, 6\)) can return any of the integers \(1, 2, 3, 4, 5,\) or \(6\).
3. Relational and Boolean Operators
To make decisions, algorithms compare values using relational operators that evaluate to either true or false:
Relational Comparisons:
a = b : tests if \(a\) is equal to \(b\). (Notice that a single equals sign is used for comparison, while <- is used for assignment!)
a != b : tests if \(a\) does not equal \(b\) (often printed with the mathematical not-equal sign \(\ne\)).
a > b, a < b, a >= b, a <= b : test greater than, less than, greater than or equal to, and less than or equal to.
Logical (Boolean) Operators:
NOT condition : Evaluates to true if the condition is false; evaluates to false if the condition is true.
condition1 AND condition2 : Evaluates to true only when both conditions are true.
condition1 OR condition2 : Evaluates to true if either condition is true, or if both are true.
4. Selection (Conditionals)
Selection allows algorithms to choose different execution paths based on Boolean conditions:
One-Way Selection:
In text notation: IF(condition) { block of statements }
If condition evaluates to true, the enclosed statements execute. If false, they are skipped entirely.
Two-Way Selection:
In text notation: IF(condition) { first block } ELSE { second block }
If condition is true, the first block executes. If false, the second block under ELSE executes. Only one of the two blocks will ever run during a single evaluation.
In block notation, these appear as bounded visual containers with an attached tab or slot for the condition expression at the top.
5. Iteration (Loops)
Iteration repeats a segment of code. The AP CSP Reference Sheet specifies two distinct loop constructs:
Count-Controlled Iteration: REPEAT n TIMES { block of statements }
The code inside the block executes exactly \(n\) times. In block format, this is represented by an enclosing block labeled with the number of repetitions.
Condition-Controlled Iteration: REPEAT UNTIL(condition) { block of statements }
Major Trap Alert: Many popular languages (like Python or Java) use while loops that continue running as long as a condition is true. The AP CSP exam uses REPEAT UNTIL, which repeats until the condition becomes true! In other words, the loop continues executing as long as the condition evaluates to false, and stops the instant the condition becomes true. If the condition is already true before the loop begins, the body does not execute even once.
6. Lists and 1-Based Indexing
A list is an ordered collection of elements. The Reference Sheet includes powerful notation for creating and manipulating lists.
CRITICAL EXAM CONVENTION: 1-Based Indexing
Unlike many languages that begin indexing at \(0\), AP CSP list indices start at \(1\)! The very first element of a list named scores is at scores[\(1\)]. If a program attempts to access an index less than \(1\) or greater than the list's total length, an error is produced and execution terminates immediately.
Essential List Commands:
aList <- [value1, value2, ...] : Creates a new list containing the given values at indices \(1, 2, ...\)
aList <- [] : Creates a brand new, empty list of length \(0\).
aList <- bList : Assigns a full copy of bList into aList.
aList[i] : Accesses the item stored at index \(i\).
x <- aList[i] : Copies the element at index \(i\) into variable \(x\).
aList[i] <- x : Replaces the element currently at index \(i\) with the value of \(x\).
aList[i] <- aList[j] : Replaces the element at index \(i\) with a copy of the item at index \(j\).
List Modification Procedures:
INSERT(aList, i, value) : Inserts value at index \(i\). Every item previously at index \(i\) or higher shifts one index to the right, and the list's length increases by \(1\).
APPEND(aList, value) : Adds value to the very end of aList, increasing the length by \(1\).
REMOVE(aList, i) : Deletes the element at index \(i\). All subsequent elements shift one spot to the left, and the list's length decreases by \(1\).
LENGTH(aList) : Evaluates to the current total number of elements in aList.
FOR EACH item IN aList { block of statements } : A complete traversal loop. The variable item successively takes on each value in aList from index \(1\) to the end of the list.
7. Procedures and RETURN
Procedures allow programmers to group statements under a named abstraction that can be called whenever needed:
Procedure Definition:
PROCEDURE procName(parameter1, parameter2, ...) { block of statements }
Defines a procedure and specifies its formal parameters.
Procedure Call:
procName(arg1, arg2, ...) executes the procedure by passing the argument values into the corresponding parameters.
The RETURN Statement:
RETURN(expression) returns the computed value back to the place where the procedure was called. For example: result <- procName(arg1, arg2). When a RETURN statement executes, it immediately ends the procedure execution and transfers control straight back to the caller—no remaining lines within that procedure are run.
8. Robot Grid Questions
The AP CSP exam frequently uses a graphical "Robot in a Grid" context to test algorithmic tracing. You will see a small robot icon placed in a square grid containing open squares and shaded obstacles or walls.
The Fundamental Collision Rule:
If the robot attempts to move forward into a square that is not open (such as a blocked wall) or attempts to walk off the edge of the grid, the robot stays in place and the entire program terminates.
Robot Commands:
MOVE_FORWARD() : Moves the robot forward one square in the direction it is currently facing.
ROTATE_LEFT() : Rotates the robot \(90^\circ\) counterclockwise in place without moving squares.
ROTATE_RIGHT() : Rotates the robot \(90^\circ\) clockwise in place without moving squares.
CAN_MOVE(direction) : Evaluates to true if there is an open square one space away in the specified direction relative to the way the robot is currently facing; otherwise evaluates to false. The valid directions are forward, backward, left, and right.
Handy Tip for Robot Problems: Physically rotate your test booklet or paper so that your view aligns with the direction the robot is facing! It makes determining relative "left" and "right" effortless.
Exam Reference Sheet Quick Review
Keep these unique AP conventions top-of-mind when analyzing code:
• Assignment: <- stores values; = checks equality.
• Output: DISPLAY() automatically adds a space after the printed item.
• Division: / calculates exact real numbers (\(17 / 5 = 3.4\)); MOD calculates integer remainders (\(17 \text{ MOD } 5 = 2\)).
• Indexing: Lists start at index \(1\), not \(0\). Out-of-bounds indices crash the program.
• Condition Loops: REPEAT UNTIL halts when the condition becomes true.
• Robot Crashes: Moving into a wall or off-grid causes the program to terminate immediately.