AP Computer Science Principles 2026 Exam Reference Guide
- This document pertains to the AP® Computer Science Principles 2026 EXAM REFERENCE INFORMATION.
- Blank space in the exam booklet may be used for scratch work during the exam.
- Proctors are required to collect this reference information at the conclusion of the exam.
- Copyright is held by © 2025 College Board.
- Assignment:
- Text: a←expression
- Block: a←expression
- Explanation: This operation evaluates the given expression and then assigns a copy of the resulting value to the variable a.
- Display:
- Text: DISPLAY(expression)
- Block: DISPLAY expression
- Explanation: This displays the value of the expression, followed by a single space.
- Input:
- Text: INPUT()
- Block: INPUT
- Explanation: This command accepts a value from the user and returns the input value.
Arithmetic Operators and Numeric Procedures
- Basic Arithmetic:
- Text and Block: a+b, a−b, a×b, a/b
- Explanation: The arithmetic operators are used to perform arithmetic on variables a and b.
- Division Example: The operation 17/5 evaluates to the value 3.4.
- Order of Operations: The standard order of operations used in mathematics applies when evaluating these expressions.
- Modulus Operator:
- Text and Block: a MOD b
- Explanation: This evaluates to the remainder when the integer a is divided by the integer b.
- Assumptions: It is assumed that a is an integer greater than or equal to 0 and b is an integer greater than 0.
- Precedence: The MOD operator has the same precedence as the multiplication (×) and division (/) operators.
- Example: The operation 17 MOD 5 evaluates to the value 2.
- Random Interger Generation:
- Text: RANDOM(a,b)
- Block: RANDOM a,b
- Explanation: This procedure generates and returns a random integer from a to b, including both the values of a and b.
- Probability: Each possible integer result is equally likely to occur.
- Example: The call RANDOM(1,3) could return the values 1, 2, or 3.
Relational and Boolean Operators
- Relational Operators:
- Text and Block Formats: a=b, a=b, a > b, a < b, a≥b, a≤b
- Explanation: These operators are used to test the relationship between two variables, expressions, or values.
- Return Type: A comparison using these operators evaluates to a Boolean value (true or false).
- Example: The expression a=b evaluates to true if a and b are equal; otherwise, it evaluates to false.
- Boolean Logic:
- NOT:
- Text: NOT condition
- Block: NOT condition
- Explanation: Evaluates to true if the condition is false; otherwise, it evaluates to false.
- AND:
- Text: condition1 AND condition2
- Block: condition1 AND condition2
- Explanation: Evaluates to true if both condition1 and condition2 are true; otherwise, it evaluates to false.
- OR:
- Text: condition1 OR condition2
- Block: condition1 OR condition2
- Explanation: Evaluates to true if condition1 is true, or if condition2 is true, or if both are true. It evaluates to false only if both conditions are false.
Selection (Conditional Statements)
- Simple IF Statement:
- Text:
IF(condition)
{
<block of statements>
}
- Block: IF condition
- Explanation: The code within the block of statements is executed only if the Boolean expression condition evaluates to true. If the condition is false, no action is taken. - IF-ELSE Statement:
- Text:
IF(condition)
{
<first block of statements>
}
ELSE
{
<second block of statements>
}
- Block: IF condition, ELSE
- Explanation: If the Boolean expression condition evaluates to true, the code in the first block of statements is executed. If the condition evaluates to false, the code in the second block of statements is executed.
Iteration (Loops)
- REPEAT n TIMES:
- Text:
REPEAT n TIMES
{
<block of statements>
}
- Block: REPEAT n TIMES
- Explanation: The code within the block of statements is executed exactly n times. - REPEAT UNTIL:
- Text:
REPEAT UNTIL(condition)
{
<block of statements>
}
- Block: REPEAT UNTIL condition
- Explanation: The code in the block of statements is repeated until the Boolean expression condition evaluates to true.
List Operations
- Error Handling: For all list operations, if a list index is less than 1 or greater than the current length of the list, an error message is produced and the program terminates.
- List Initialization:
- Text: aList←[value1, value2, value3, …]
- Block: aList←value1, value2, value3
- Explanation: Creates a new list containing specified values at indices 1, 2, 3, and so on, and assigns it to aList.
- Empty List Creation:
- Text: aList←[]
- Block: aList←[]
- Explanation: Creates an empty list and assigns it to aList.
- List Copying:
- Text: aList←bList
- Block: aList←bList
- Explanation: Assigns a copy of the list bList to the list aList.
- Example: If bList contains [20,40,60], then aList will also contain [20,40,60] after assignment.
- Accessing Elements:
- Text: aList[i]
- Block: aList i
- Explanation: Accesses the element of aList at the specified index i.
- First Element: The first element is always at index 1 and is accessed as aList[1].
- Assigning from a List:
- Text: x←aList[i]
- Block: x←aList i
- Explanation: Assigns the value found at aList[i] to the variable x.
- Assigning to a List:
- Text: aList[i]←x
- Block: aList i←x
- Explanation: Assigns the value of x to the component at aList[i].
- Assigning Between List Indices:
- Text: aList[i]←aList[j]
- Block: aList i←aList j
- Explanation: Assigns the value of aList[j] to the position aList[i].
- Inserting Elements:
- Text: INSERT(aList,i,value)
- Block: INSERT aList, i, value
- Explanation: Any values in aList at indices greater than or equal to i are shifted one position to the right. The length of the list increases by 1, and the new value is placed at index i.
- Appending Elements:
- Text: APPEND(aList, value)
- Block: APPEND aList, value
- Explanation: The length of aList is increased by 1, and the value is placed at the end of the list.
- Removing Elements:
- Text: REMOVE(aList,i)
- Block: REMOVE aList, i
- Explanation: Removes the item at index i in aList and shifts to the left any values at indices greater than i. The length of the list is decreased by 1.
- List Length:
- Text: LENGTH(aList)
- Block: LENGTH aList
- Explanation: Evaluates to the total number of elements currently in aList.
- List Traversal:
- Text:
FOR EACH item IN aList
{
<block of statements>
}
- Block: FOR EACH item IN aList
- Explanation: The variable item is assigned the value of each element of aList sequentially from first to last. The code in the block of statements executes once for each assignment of item.
Procedures and Procedure Calls
- Procedure Definition without Return Value:
- Text:
PROCEDURE procName(parameter1, parameter2, ...)
{
<block of statements>
}
- Block: PROCEDURE procName parameter1, parameter2, …
- Explanation: Defines procName as a procedure taking zero or more arguments. To call it, use procName(arg1, arg2, …). - Procedure Definition with Return Value:
- Text:
PROCEDURE procName(parameter1, parameter2, ...)
{
<block of statements>
RETURN(expression)
}
- Block: PROCEDURE procName parameter1, parameter2, … RETURN expression
- Explanation: Defines a procedure that returns the value of expression. The result can be assigned to a variable: result←procName(arg1, arg2, …). - RETURN Statement:
- Text: RETURN(expression)
- Block: RETURN expression
- Explanation: Returns control flow to the point where the procedure was called and returns the evaluated expression value. It causes an immediate return from the procedure.
Robot Operations
- Collision and Boundary Rules: If the robot attempts to move to a square that is not open or is beyond the grid edge, the robot stays in its current location and the program terminates.
- Move Forward:
- Text: \text{MOVE_FORWARD}()
- Block: \text{MOVE_FORWARD}
- Explanation: The robot moves one square forward in its current facing direction.
- Rotate Left:
- Text: \text{ROTATE_LEFT}()
- Block: \text{ROTATE_LEFT}
- Explanation: The robot rotates 90 degrees counterclockwise in place.
- Rotate Right:
- Text: \text{ROTATE_RIGHT}()
- Block: \text{ROTATE_RIGHT}
- Explanation: The robot rotates 90 degrees clockwise in place.
- Sensing Boundaries (CAN_MOVE):
- Text: \text{CAN_MOVE}(\text{direction})
- Block: \text{CAN_MOVE direction}
- Explanation: Evaluates to true if there is an open square one square away in the specified direction relative to where the robot is facing; otherwise, it evaluates to false.
- Valid Directions: The value of direction can be left, right, forward, or backward.