AP Computer Science Principles 2026 Exam Reference Guide

Exam Reference General Information

  • 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, Display, and Input

  • Assignment:   - Text: aexpressiona \leftarrow \text{expression}   - Block: aexpressiona \leftarrow \text{expression}   - Explanation: This operation evaluates the given expression\text{expression} and then assigns a copy of the resulting value to the variable aa.
  • Display:   - Text: DISPLAY(expression)\text{DISPLAY}(\text{expression})   - Block: DISPLAY expression\text{DISPLAY expression}   - Explanation: This displays the value of the expression\text{expression}, followed by a single space.
  • Input:   - Text: INPUT()\text{INPUT}()   - Block: INPUT\text{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+ba + b, aba - b, a×ba \times b, a/ba / b   - Explanation: The arithmetic operators are used to perform arithmetic on variables aa and bb.   - Division Example: The operation 17/517 / 5 evaluates to the value 3.43.4.   - Order of Operations: The standard order of operations used in mathematics applies when evaluating these expressions.
  • Modulus Operator:   - Text and Block: a MOD ba \text{ MOD } b   - Explanation: This evaluates to the remainder when the integer aa is divided by the integer bb.   - Assumptions: It is assumed that aa is an integer greater than or equal to 00 and bb is an integer greater than 00.   - Precedence: The MOD\text{MOD} operator has the same precedence as the multiplication (×\times) and division (//) operators.   - Example: The operation 17 MOD 517 \text{ MOD } 5 evaluates to the value 22.
  • Random Interger Generation:   - Text: RANDOM(a,b)\text{RANDOM}(a, b)   - Block: RANDOM a,b\text{RANDOM } a, b   - Explanation: This procedure generates and returns a random integer from aa to bb, including both the values of aa and bb.   - Probability: Each possible integer result is equally likely to occur.   - Example: The call RANDOM(1,3)\text{RANDOM}(1, 3) could return the values 11, 22, or 33.

Relational and Boolean Operators

  • Relational Operators:   - Text and Block Formats: a=ba = b, aba \neq b, a > b, a < b, aba \geq b, aba \leq 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\text{true} or false\text{false}).   - Example: The expression a=ba = b evaluates to true\text{true} if aa and bb are equal; otherwise, it evaluates to false\text{false}.
  • Boolean Logic:   - NOT:     - Text: NOT condition\text{NOT condition}     - Block: NOT condition\text{NOT condition}     - Explanation: Evaluates to true\text{true} if the condition\text{condition} is false\text{false}; otherwise, it evaluates to false\text{false}.   - AND:     - Text: condition1 AND condition2\text{condition1 AND condition2}     - Block: condition1 AND condition2\text{condition1 AND condition2}     - Explanation: Evaluates to true\text{true} if both condition1\text{condition1} and condition2\text{condition2} are true\text{true}; otherwise, it evaluates to false\text{false}.   - OR:     - Text: condition1 OR condition2\text{condition1 OR condition2}     - Block: condition1 OR condition2\text{condition1 OR condition2}     - Explanation: Evaluates to true\text{true} if condition1\text{condition1} is true\text{true}, or if condition2\text{condition2} is true\text{true}, or if both are true\text{true}. It evaluates to false\text{false} only if both conditions are false\text{false}.

Selection (Conditional Statements)

  • Simple IF Statement:     - Text: IF(condition) { <block of statements> } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     - Block: IF condition\text{IF condition}     - Explanation: The code within the block of statements\text{block of statements} is executed only if the Boolean expression condition\text{condition} evaluates to true\text{true}. If the condition is false\text{false}, no action is taken.
  • IF-ELSE Statement:     - Text: IF(condition) { <first block of statements> } ELSE { <second block of statements> } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     - Block: IF condition\text{IF condition}, ELSE\text{ELSE}     - Explanation: If the Boolean expression condition\text{condition} evaluates to true\text{true}, the code in the first block of statements\text{first block of statements} is executed. If the condition evaluates to false\text{false}, the code in the second block of statements\text{second block of statements} is executed.

Iteration (Loops)

  • REPEAT n TIMES:   - Text: REPEAT n TIMES { <block of statements> } &nbsp;&nbsp;&nbsp;&nbsp;   - Block: REPEAT n TIMES\text{REPEAT } n \text{ TIMES}   - Explanation: The code within the block of statements\text{block of statements} is executed exactly nn times.
  • REPEAT UNTIL:   - Text: REPEAT UNTIL(condition) { <block of statements> } &nbsp;&nbsp;&nbsp;&nbsp;   - Block: REPEAT UNTIL condition\text{REPEAT UNTIL condition}   - Explanation: The code in the block of statements\text{block of statements} is repeated until the Boolean expression condition\text{condition} evaluates to true\text{true}.

List Operations

  • Error Handling: For all list operations, if a list index is less than 11 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, ]\text{aList} \leftarrow [\text{value1, value2, value3, …}]   - Block: aListvalue1, value2, value3\text{aList} \leftarrow \text{value1, value2, value3}   - Explanation: Creates a new list containing specified values at indices 11, 22, 33, and so on, and assigns it to aList\text{aList}.
  • Empty List Creation:   - Text: aList[]\text{aList} \leftarrow []   - Block: aList[]\text{aList} \leftarrow []   - Explanation: Creates an empty list and assigns it to aList\text{aList}.
  • List Copying:   - Text: aListbList\text{aList} \leftarrow \text{bList}   - Block: aListbList\text{aList} \leftarrow \text{bList}   - Explanation: Assigns a copy of the list bList\text{bList} to the list aList\text{aList}.   - Example: If bList\text{bList} contains [20,40,60][20, 40, 60], then aList\text{aList} will also contain [20,40,60][20, 40, 60] after assignment.
  • Accessing Elements:   - Text: aList[i]\text{aList}[i]   - Block: aList i\text{aList } i   - Explanation: Accesses the element of aList\text{aList} at the specified index ii.   - First Element: The first element is always at index 11 and is accessed as aList[1]\text{aList}[1].
  • Assigning from a List:   - Text: xaList[i]x \leftarrow \text{aList}[i]   - Block: xaList ix \leftarrow \text{aList } i   - Explanation: Assigns the value found at aList[i]\text{aList}[i] to the variable xx.
  • Assigning to a List:   - Text: aList[i]x\text{aList}[i] \leftarrow x   - Block: aList ix\text{aList } i \leftarrow x   - Explanation: Assigns the value of xx to the component at aList[i]\text{aList}[i].
  • Assigning Between List Indices:   - Text: aList[i]aList[j]\text{aList}[i] \leftarrow \text{aList}[j]   - Block: aList iaList j\text{aList } i \leftarrow \text{aList } j   - Explanation: Assigns the value of aList[j]\text{aList}[j] to the position aList[i]\text{aList}[i].
  • Inserting Elements:   - Text: INSERT(aList,i,value)\text{INSERT}(\text{aList}, i, \text{value})   - Block: INSERT aList, i, value\text{INSERT aList, } i, \text{ value}   - Explanation: Any values in aList\text{aList} at indices greater than or equal to ii are shifted one position to the right. The length of the list increases by 11, and the new value\text{value} is placed at index ii.
  • Appending Elements:   - Text: APPEND(aList, value)\text{APPEND}(\text{aList, value})   - Block: APPEND aList, value\text{APPEND aList, value}   - Explanation: The length of aList\text{aList} is increased by 11, and the value\text{value} is placed at the end of the list.
  • Removing Elements:   - Text: REMOVE(aList,i)\text{REMOVE}(\text{aList}, i)   - Block: REMOVE aList, i\text{REMOVE aList, } i   - Explanation: Removes the item at index ii in aList\text{aList} and shifts to the left any values at indices greater than ii. The length of the list is decreased by 11.
  • List Length:   - Text: LENGTH(aList)\text{LENGTH}(\text{aList})   - Block: LENGTH aList\text{LENGTH aList}   - Explanation: Evaluates to the total number of elements currently in aList\text{aList}.
  • List Traversal:   - Text: FOR EACH item IN aList { <block of statements> } &nbsp;&nbsp;&nbsp;&nbsp;   - Block: FOR EACH item IN aList\text{FOR EACH item IN aList}   - Explanation: The variable item\text{item} is assigned the value of each element of aList\text{aList} sequentially from first to last. The code in the block of statements\text{block of statements} executes once for each assignment of item\text{item}.

Procedures and Procedure Calls

  • Procedure Definition without Return Value:   - Text: PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> } &nbsp;&nbsp;&nbsp;&nbsp;   - Block: PROCEDURE procName parameter1, parameter2, \text{PROCEDURE procName parameter1, parameter2, …}   - Explanation: Defines procName\text{procName} as a procedure taking zero or more arguments. To call it, use procName(arg1, arg2, )\text{procName}(\text{arg1, arg2, …}).
  • Procedure Definition with Return Value:   - Text: PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) } &nbsp;&nbsp;&nbsp;&nbsp;   - Block: PROCEDURE procName parameter1, parameter2,  RETURN expression\text{PROCEDURE procName parameter1, parameter2, … RETURN expression}   - Explanation: Defines a procedure that returns the value of expression\text{expression}. The result can be assigned to a variable: resultprocName(arg1, arg2, )\text{result} \leftarrow \text{procName}(\text{arg1, arg2, …}).
  • RETURN Statement:   - Text: RETURN(expression)\text{RETURN}(\text{expression})   - Block: RETURN expression\text{RETURN expression}   - Explanation: Returns control flow to the point where the procedure was called and returns the evaluated expression\text{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 9090 degrees counterclockwise in place.
  • Rotate Right:   - Text: \text{ROTATE_RIGHT}()   - Block: \text{ROTATE_RIGHT}   - Explanation: The robot rotates 9090 degrees clockwise in place.
  • Sensing Boundaries (CAN_MOVE):   - Text: \text{CAN_MOVE}(\text{direction})   - Block: \text{CAN_MOVE direction}   - Explanation: Evaluates to true\text{true} if there is an open square one square away in the specified direction\text{direction} relative to where the robot is facing; otherwise, it evaluates to false\text{false}.   - Valid Directions: The value of direction\text{direction} can be left\text{left}, right\text{right}, forward\text{forward}, or backward\text{backward}.