TLDR
Mathematical expressions in AP Computer Science Principles are about evaluating arithmetic to a single value and putting steps in the right order. You need to know the five arithmetic operators (+, -, *, /, MOD), how MOD finds a remainder, and how order of operations decides what gets evaluated first. Sequencing means statements run top to bottom in the order they appear.

Why This Matters for the AP Computer Science Principles Exam
This topic builds the foundation for almost every code segment you will read on the exam. Multiple-choice questions often ask you to determine the result of a code segment, and that usually starts with evaluating an expression correctly. The exam uses its own pseudocode on a reference sheet, so being comfortable with operators like MOD and the / symbol is a regular requirement.
Beyond multiple-choice, expressing an algorithm using sequencing without a programming language shows up when you describe steps in natural language, a diagram, or pseudocode. When you build your program for the Create performance task, sequencing and arithmetic are the basic moves you combine into larger logic.
Key Takeaways
- An algorithm is a finite set of instructions that accomplishes a specific task, and it can be written as natural language, a diagram, or pseudocode, not only in a programming language.
- Every algorithm can be built from combinations of sequencing, selection, and iteration.
- Sequencing means each statement runs in the order it appears, one after another.
- An expression can be a value, a variable, an operator, or a procedure call that returns a value, and it always evaluates to a single value.
- The arithmetic operators are
+,-,*,/, andMOD;a MOD bgives the remainder whenais divided byb. - Order of operations decides what evaluates first, and on the exam reference sheet
MODhas the same precedence as*and/.
Algorithms and Sequencing
An algorithm is a finite set of instructions that accomplishes a specific task. That definition sounds a lot like a program, and the two are closely related, but they are not the same thing. An algorithm is the problem-solving logic, while a program is how you carry it out. Programs execute algorithms.
Think of baking a cake. The algorithm is the set of steps you follow to make the cake. The program is the written recipe that the baker, or the computer, actually runs.
Algorithms can be expressed in many ways. You can write one in a programming language like Java or a block-based language like Scratch for a computer to run. You can also write it in pseudocode, describe it in a natural language like English, or draw it as a diagram. A computer does exactly what you tell it, so be clear and detailed when you turn an algorithm in your head into a program.
Sequencing, Selection, and Iteration
Every algorithm can be constructed from three building blocks: sequencing, selection, and iteration. These are carried out through code statements, which are parts of program code that express an action to be carried out.
Sequencing is the application of each step in the order the code statements are given. Once one statement runs, the program moves on to the next one.
</>Codefirst_number = 7 second_number = 5 sum_value = first_number + second_number print (sum_value)
The computer reads and processes these one after another, top to bottom. Selection and iteration come later in this unit and let you make decisions and repeat steps.
Expressions
An expression can consist of a value, a variable, an operator, or a procedure call that returns a value. The important part is that an expression always evaluates to a single value.
So 7, first_number, first_number + second_number, and a procedure call that hands back a number are all expressions. Each one resolves to one value when the program runs.
Arithmetic Operators
Programs use arithmetic operators for addition, subtraction, multiplication, division, and modulus. On the AP exam reference sheet, the operators are written like this:
a + baddsaandba - bsubtractsbfromaa * bmultipliesaandba / bdividesabyb, so17 / 5evaluates to3.4a MOD bgives the remainder whenais divided byb, so17 MOD 5evaluates to2
Notice that / can produce a decimal result on the reference sheet, which is why 17 / 5 is 3.4 and not 3.
The MOD Operator
MOD is short for modulus, and a MOD b gives the remainder of a divided by b. For example, 13 MOD 3 evaluates to 1, because 13 divided by 3 is 4 with a remainder of 1. On the reference sheet, a is assumed to be an integer greater than or equal to 0, and b is an integer greater than 0.
MOD shows up constantly in exam questions. It is the standard tool for checking even or odd numbers (n MOD 2 is 0 for even numbers) and for finding remainders in counting or grouping problems.
🔗 Code.org made a visual called the Modulo Clock that shows how MOD wraps around as numbers increase.
Order of Operations
Expressions are evaluated using an order of operations defined by the programming language, and it generally follows the same PEMDAS rules you use in math. Parentheses first, then multiplication and division, then addition and subtraction, working left to right when operators have equal precedence.
The one detail to memorize is that on the exam reference sheet, MOD has the same precedence as * and /. That means in an expression with multiplication, division, and MOD mixed together, you evaluate them left to right in the order they appear.
When in doubt, use parentheses. They override the default precedence and make your intended order clear, which also makes your code easier to read.
How to Use This on the AP Computer Science Principles Exam
Code Tracing
When a multiple-choice question asks you to determine the result of a code segment, slow down and evaluate one expression at a time. Substitute the current value of each variable, apply order of operations, and reduce the expression to a single value before moving to the next statement.
Common Trap
Watch the MOD and / results carefully. Mixing up a remainder (MOD) with a quotient (/) is one of the easiest mistakes to make under time pressure. Write out the division as quotient plus remainder if you need to.
Representing Algorithms Without Code
Some questions or the Create performance task ask you to express steps as an algorithm. You can use natural language, a diagram, or pseudocode. Keep the steps in clear sequential order so the logic is easy to follow.
Common Misconceptions
- An algorithm and a program are not identical. The algorithm is the logic, and the program is the specific implementation that carries it out.
MODdoes not give you the result of the division. It gives the remainder only.17 / 5is3.4, but17 MOD 5is2.- Division on the reference sheet can return a decimal. Do not assume
17 / 5truncates to3. MODdoes not come after multiplication and division in precedence. It shares the same precedence level as*and/, so you work left to right among them.- Algorithms are not limited to code. They can be written in natural language, drawn as diagrams, or written in pseudocode.
- Sequencing is not just a minor detail. Changing the order of statements can change the result, since each statement runs in the order it appears.
Related AP Computer Science Principles Guides
Vocabulary
The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.Term | Definition |
|---|---|
addition | An arithmetic operation represented by the + symbol that combines two numbers to produce their sum. |
algorithm | Step-by-step procedures or sets of rules designed to solve a problem or accomplish a task. |
arithmetic operators | Symbols used in programming to perform mathematical operations, including addition, subtraction, multiplication, division, and modulus. |
code statement | A part of program code that expresses an action to be carried out. |
division | An arithmetic operation represented by the / symbol that splits one number by another to produce a quotient. |
expression | A combination of a value, variable, operator, or procedure call that can be evaluated to produce a single value. |
iteration | A repeating portion of an algorithm that executes a specified number of times or until a given condition is met. |
modulus operator | An arithmetic operator represented as MOD that evaluates to the remainder when one integer is divided by another. |
multiplication | An arithmetic operation represented by the * symbol that combines two numbers to produce their product. |
operator | A symbol or keyword that performs an operation on one or more values or variables. |
order of operations | The set of rules that specifies which calculations to perform first in a mathematical expression, with MOD having the same precedence as multiplication and division. |
procedure call | A statement that executes a named procedure, interrupting sequential execution and transferring control to the procedure. |
pseudocode | A method of expressing an algorithm using a combination of natural language and programming-like syntax, independent of any specific programming language. |
selection | A control structure that determines which parts of an algorithm are executed based on whether a condition is true or false. |
sequencing | The application of each step of an algorithm in the order in which the code statements are given. |
sequential code statements | Lines of code that are executed in the order they appear, one after another. |
subtraction | An arithmetic operation represented by the - symbol that finds the difference between two numbers. |
variable | A named container in a program that stores a value which can be changed through assignment. |
Frequently Asked Questions
What are mathematical expressions in AP CSP?
Mathematical expressions are values, variables, operators, or procedure calls that evaluate to one value when a program runs.
What does MOD mean in AP CSP?
MOD gives the remainder after division. For example, 17 MOD 5 evaluates to 2 because 17 divided by 5 has remainder 2.
What arithmetic operators are on the AP CSP reference sheet?
The AP CSP reference sheet includes +, -, *, /, and MOD for arithmetic expressions.
What is the order of operations for MOD?
MOD has the same precedence as multiplication and division, so expressions using *, /, and MOD are evaluated left to right unless parentheses change the order.
What is sequencing in AP CSP?
Sequencing means statements execute in the order they appear, one after another. Changing the order can change the result.
How are mathematical expressions tested on the AP CSP exam?
You may need to trace code, substitute variable values, evaluate arithmetic expressions, apply MOD, and follow sequencing to determine a code segment's result.