AP Computer Science Principles 2026 Exam Reference Guide

Assignment, Display, and Input

  • Assignment Operators:     - Text Representation: a ← expression     - Block Representation: a ← expression     - Functionality: Evaluates the expression and then assigns a copy of the resulting value to the variable aa.

  • Display Operation:     - Text Representation: DISPLAY(expression)     - Block Representation: DISPLAY expression     - Functionality: Displays the value of the expression to the user, followed by a trailing space.

  • Input Operation:     - Text Representation: INPUT()     - Block Representation: INPUT     - Functionality: Accepts a value provided by the user and returns that input value to the program.

Arithmetic Operators and Numeric Procedures

  • Basic Arithmetic Operators:     - Operators: +, -, *, and /.     - Usage: Used to perform addition, subtraction, multiplication, and division on operands aa and bb.     - Division Behavior: Division results in a decimal value where applicable. For example, 175\frac{17}{5} evaluates to 3.43.4.     - Order of Operations: Standard mathematical precedence rules (PEMDAS/BODMAS) apply when evaluating expressions.

  • Modulus Operator (MOD):     - Text and Block Representation: a MOD b     - Functionality: Evaluates to the remainder when the integer aa is divided by the integer bb.     - Constraints:         - aa must be an integer greater than or equal to 00 (a0a \ge 0).         - bb must be an integer greater than 00 (b > 0).     - Example: 17 MOD 517 \text{ MOD } 5 evaluates to 22.     - Precedence: The MOD operator has the same level of precedence as the multiplication (*) and division (/) operators.

  • Random Number Generation:     - Text Representation: RANDOM(a, b)     - Block Representation: RANDOM a, b     - Functionality: Generates and returns a random integer within the range from aa to bb, inclusive of both endpoints.     - **Probability**: Each integer result within the specified range is equally likely to occur.     - **Example**:RANDOM(1, 3)can return the values11, 22, or33.

Relational and Boolean Operators

  • Relational Operators:     - Operators: =, , >, <, , .     - Functionality: Used to test the relationship between two variables, expressions, or values.     - Return Value: A comparison using these operators always evaluates to a Boolean value (true or false).     - Equivalence Example: a = b evaluates to true if aa and bb are equal; otherwise, it evaluates to false.

  • 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 if both condition1 and condition2 are true.         - Evaluates to false otherwise.     - condition1 OR condition2:         - Evaluates to true if condition1 is true, OR if condition2 is true, OR if both are true.         - Evaluates to false only if both conditions are false.

Selection (Conditional Statements)

  • Standard IF-Statement:     - Structure: IF(condition) { <block of statements> }     - Logic: The code inside the block is executed if the Boolean expression condition evaluates to true. If the condition is false, no action is taken and the block is skipped.

  • IF-ELSE Statement:     - Structure: IF(condition) { <first block of statements> } ELSE { <second block of statements> }     - Logic: If the condition is true, the first block of statements is executed. If the condition is false, the second block of statements (within the ELSE clause) is executed.

Iteration (Loops)

  • Count-Controlled Loop:     - Structure: REPEAT n TIMES { <block of statements> }     - Logic: The code within the block is executed exactly nn times.

  • Condition-Controlled Loop:     - Structure: REPEAT UNTIL(condition) { <block of statements> }     - Logic: The code within the block is repeated continuously until the Boolean expression condition evaluates to true. If the condition is initially true, the block is never executed.

List Operations

  • General Indexing Rules:     - Starting Index: The first element of a list is at index 11. &nbsp;&nbsp;&nbsp;&nbsp;- **Error Handling**: If a list index is less than11` or greater than the current length of the list, the program produces an error message and terminates immediately.

  • List Creation and Assignment:     - Initial Hierarchy: aList ← [value1, value2, value3, ...] creates a list with elements at indices 1,2,3,...1, 2, 3, ....     - Empty List: aList ← [] creates an empty list and assigns it to aList.     - Copying Lists: aList ← bList assigns a full copy of bList to aList.         - Example: If bList is [20, 40, 60], then aList becomes [20, 40, 60] after the assignment.

  • Accessing and Modifying Elements:     - Access: aList[i] retrieves the element at index ii. &nbsp;&nbsp;&nbsp;&nbsp;- **Variable Retrieval**:x ← aList[i]assigns the value at indexiito the variablexx.     - Value Update: aList[i] ← x replaces the element at index ii with xx. &nbsp;&nbsp;&nbsp;&nbsp;- **Index-to-Index Assignment**:aList[i] ← aList[j]assigns the value found at indexjjto the position at indexii.

  • List Manipulation Procedures:     - INSERT(aList, i, value):         - Elements at indices greater than or equal to ii are shifted one position to the right.         - The length of the list increases by 11. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- The newvalueis placed at indexii.     - APPEND(aList, value):         - The length of the list increases by 11. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- The newvalueis placed at the very end of the list. &nbsp;&nbsp;&nbsp;&nbsp;- **REMOVE(aList, i)**: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Removes the item at indexii.         - Shifts all elements at indices greater than ii one position to the left.         - The length of the list decreases by 11. &nbsp;&nbsp;&nbsp;&nbsp;- **LENGTH(aList)**: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Evaluates to the total number of elements currently stored inaList`.

  • List Traversal:     - Structure: FOR EACH item IN aList { <block of statements> }     - Logic: The variable item is sequentially assigned the value of every element in the list, starting from the first element and ending with the last. The block of statements executes once for every element in the list.

Procedures and Procedure Calls

  • Procedure Definition without Return:     - Structure: PROCEDURE procName(parameter1, parameter2, ...)     - Logic: Defines a procedure that accepts zero or more arguments. Arguments are assigned to parameters during the call.

  • Procedure Definition with Return:     - Structure: PROCEDURE procName(parameter1, parameter2, ...) { <block> RETURN(expression) }     - Logic: Defines a procedure that returns a specific value using the RETURN statement.     - The RETURN Statement:         - Causes an immediate exit from the procedure.         - Returns flow of control to the calling statement.         - Passes the value of expression back to the caller.         - Can be used for assignment: result ← procName(arg1, arg2, ...).

Robot Commands

  • Movement and Safety Rules:     - If the robot attempts to move into a square that is not open (e.g., a wall) or past the grid's edge, the robot remains in its current square and the entire program terminates.

  • Action Commands:     - MOVE_FORWARD(): The robot moves one square ahead in its current direction.     - ROTATE_LEFT(): The robot turns 9090^∘ counterclockwise in place.     - ROTATE_RIGHT(): The robot turns 9090^∘ clockwise in place.

  • Sensing Command:     - CAN_MOVE(direction):         - Evaluates to true if the square one position away in the specified direction is open.         - Evaluates to false if the square is occupied or is the edge of the grid.         - Valid Directions: left, right, forward, or backward (relative to the robot's current orientation).