AP Computer Science Principles 2026 Exam Reference Guide
Assignment, Display, and Input
Assignment Operators: - Text Representation:
a ← expression- Block Representation:a ← expression- Functionality: Evaluates theexpressionand then assigns a copy of the resulting value to the variable.Display Operation: - Text Representation:
DISPLAY(expression)- Block Representation:DISPLAY expression- Functionality: Displays the value of theexpressionto 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 operandsand. - Division Behavior: Division results in a decimal value where applicable. For example,evaluates to. - 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 integeris divided by the integer. - Constraints: -must be an integer greater than or equal to(). -must be an integer greater than(b > 0). - Example:evaluates to. - Precedence: TheMODoperator 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 fromto, inclusive of both endpoints. - **Probability**: Each integer result within the specified range is equally likely to occur. - **Example**:RANDOM(1, 3)can return the values,, or.
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 (trueorfalse). - Equivalence Example:a = bevaluates totrueifandare equal; otherwise, it evaluates tofalse.Boolean Operators: - NOT condition: - Evaluates to
trueif theconditionisfalse. - Evaluates tofalseif theconditionistrue. - condition1 AND condition2: - Evaluates totrueonly if bothcondition1andcondition2aretrue. - Evaluates tofalseotherwise. - condition1 OR condition2: - Evaluates totrueifcondition1istrue, OR ifcondition2istrue, OR if both aretrue. - Evaluates tofalseonly if both conditions arefalse.
Selection (Conditional Statements)
Standard IF-Statement: - Structure:
IF(condition) { <block of statements> }- Logic: The code inside the block is executed if the Boolean expressionconditionevaluates totrue. If the condition isfalse, 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 theconditionistrue, the first block of statements is executed. If theconditionisfalse, the second block of statements (within theELSEclause) is executed.
Iteration (Loops)
Count-Controlled Loop: - Structure:
REPEAT n TIMES { <block of statements> }- Logic: The code within the block is executed exactlytimes.Condition-Controlled Loop: - Structure:
REPEAT UNTIL(condition) { <block of statements> }- Logic: The code within the block is repeated continuously until the Boolean expressionconditionevaluates totrue. If the condition is initiallytrue, the block is never executed.
List Operations
General Indexing Rules: - Starting Index: The first element of a list is at index
. - **Error Handling**: If a list index is less than` 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. - Empty List:aList ← []creates an empty list and assigns it toaList. - Copying Lists:aList ← bListassigns a full copy ofbListtoaList. - Example: IfbListis[20, 40, 60], thenaListbecomes[20, 40, 60]after the assignment.Accessing and Modifying Elements: - Access:
aList[i]retrieves the element at index. - **Variable Retrieval**:x ← aList[i]assigns the value at indexto the variable. - Value Update:aList[i] ← xreplaces the element at indexwith. - **Index-to-Index Assignment**:aList[i] ← aList[j]assigns the value found at indexto the position at index.List Manipulation Procedures: - INSERT(aList, i, value): - Elements at indices greater than or equal to
are shifted one position to the right. - The length of the list increases by. - The newvalueis placed at index. - APPEND(aList, value): - The length of the list increases by. - The newvalueis placed at the very end of the list. - **REMOVE(aList, i)**: - Removes the item at index. - Shifts all elements at indices greater thanone position to the left. - The length of the list decreases by. - **LENGTH(aList)**: - Evaluates to the total number of elements currently stored inaList`.List Traversal: - Structure:
FOR EACH item IN aList { <block of statements> }- Logic: The variableitemis 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 theRETURNstatement. - The RETURN Statement: - Causes an immediate exit from the procedure. - Returns flow of control to the calling statement. - Passes the value ofexpressionback 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
counterclockwise in place. - ROTATE_RIGHT(): The robot turnsclockwise in place.Sensing Command: - CAN_MOVE(direction): - Evaluates to
trueif the square one position away in the specifieddirectionis open. - Evaluates tofalseif the square is occupied or is the edge of the grid. - Valid Directions:left,right,forward, orbackward(relative to the robot's current orientation).