How do programs evaluate arithmetic, MOD and Boolean expressions, and how do logical operators combine conditions?
Topic 3.3/3.5 Mathematical and Boolean Expressions: programs evaluate arithmetic (including MOD) and Boolean expressions using relational and logical operators (AND, OR, NOT) that produce true or false.
A focused answer to AP CSP Topics 3.3 and 3.5, covering arithmetic operators and the MOD operator, relational operators, the Boolean operators AND, OR and NOT with truth tables, evaluating compound conditions, and the common uses of MOD such as testing even or odd.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topics 3.3 and 3.5) wants you to evaluate mathematical and Boolean expressions. Mathematical expressions use the arithmetic operators (+, -, *, /) and the MOD operator (the remainder). Boolean expressions use relational operators (=, not equal, >, <, and so on) and the logical operators AND, OR and NOT, and they evaluate to true or false. You need their results, the order of evaluation, and common patterns such as using MOD to test divisibility.
Arithmetic and the MOD operator
MOD is one of the most useful operators in CSP:
- Even or odd.
n MOD 2is 0 whennis even, 1 whennis odd. - Divisibility.
n MOD k = 0meansnis divisible byk. - Wrapping/cycling.
index MOD lengthkeeps an index within a range.
Note that MOD and / answer different questions about the same division. / gives the quotient (how many whole times one number goes into another, or the exact decimal), while MOD gives the remainder (what is left over). For 17 and 5, the quotient is 3 and the remainder is 2, because 5 goes into 17 three times with 2 left over. Most divisibility and cycling logic uses the remainder, so MOD appears constantly in algorithms.
Relational operators
Relational operators compare two values and produce a Boolean:
a = b(equal),a not equal b(not equal)a > b,a < b,a >= b,a <= b
For example 5 > 3 is true; 4 = 7 is false.
Boolean operators
Truth-table essentials:
true AND trueis true; every otherANDis false.false OR falseis false; every otherORis true.NOT trueis false;NOT falseis true.
Order of evaluation: relational comparisons first, then NOT, then AND, then OR. Parentheses make grouping explicit.
Boolean expressions are the engine of decision making. The condition in every IF statement and the stopping condition of every REPEAT UNTIL loop is a Boolean expression. Being able to evaluate a compound condition by hand, applying the relational comparisons first and then combining with AND, OR and NOT, is exactly the skill the multiple-choice exam tests when it shows a code segment and asks what it does. A small slip in operator order changes the whole result, so trace these carefully rather than guessing.
Try this
Q1. What does 23 MOD 4 evaluate to? [1 point]
- Cue.
4 x 5 = 20, remainder23 - 20 = 3. So23 MOD 4is 3.
Q2. State the value of NOT (5 < 2) OR (1 > 9). [1 point]
- Cue.
5 < 2is false,NOT falseis true;1 > 9is false;true OR falseis true.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2021 (style)1 marksMultiple choice. In AP CSP pseudocode, what does the expression `17 MOD 5` evaluate to?
(A) 3
(B) 3.4
(C) 2
(D) 12
Show worked answer →
The answer is (C).
MOD gives the remainder after integer division. 17 / 5 is 3 with a remainder of 2, because 5 x 3 = 15 and 17 - 15 = 2. So 17 MOD 5 is 2. (A) 3 is the quotient, not the remainder. (B) 3.4 is the decimal division. (D) 12 is unrelated.
Markers reward knowing that MOD returns the remainder, which is the key to testing divisibility (a MOD b being 0 means a is divisible by b).
AP 2022 (style)2 marksFree response (short). State the value (true or false) of `(NOT (4 > 6)) AND (3 = 3)`, and explain the order in which the operators are evaluated.
Show worked answer →
A 2-point question on Boolean operator evaluation and precedence.
Point 1 (value): The result is true. 4 > 6 is false; NOT false is true; 3 = 3 is true; true AND true is true.
Point 2 (order): Relational comparisons are evaluated first (4 > 6 is false, 3 = 3 is true), then NOT is applied to its operand, then AND combines the two results. So the evaluation order is relational, then NOT, then AND. A common error is evaluating AND before NOT.
Related dot points
- Topic 3.1 Variables and Assignments: a variable is a named reference to a stored value, and the assignment operator stores the value of an expression into a variable.
A focused answer to AP CSP Topics 3.1 to 3.3, covering variables as named storage, the assignment operator (the arrow) in AP CSP pseudocode, evaluating the right side first, updating variables, data types, and tracing assignment statements.
- Topic 3.6/3.7 Conditionals and Nested Conditionals: conditional (IF/ELSE) statements select which code runs based on a Boolean condition, and nested conditionals handle multiple decision paths.
A focused answer to AP CSP Topics 3.6 and 3.7, covering IF and IF/ELSE selection, the role of the Boolean condition, nested conditionals for multiple paths, tracing which branch runs, and writing decision logic in AP CSP pseudocode.
- Topic 3.8 Iteration: iteration (REPEAT n TIMES and REPEAT UNTIL) repeats a block of code, with the number of repetitions controlled by a count or a condition.
A focused answer to AP CSP Topic 3.8, covering REPEAT n TIMES and REPEAT UNTIL loops in AP CSP pseudocode, counting iterations, accumulating values, infinite loops and off-by-one errors, and tracing loop execution.
- Topic 3.9 Developing Algorithms: an algorithm is a finite set of instructions that accomplishes a task, built by combining sequencing, selection and iteration, and different algorithms can solve the same problem.
A focused answer to AP CSP Topic 3.9, covering what an algorithm is, the three building blocks (sequencing, selection, iteration), expressing algorithms in pseudocode and language, that different algorithms can solve the same problem, and standard list algorithms.
- Topic 3.15/3.16 Random Values and Simulations: simulations are simplified, abstract models of real phenomena that often use random values to represent variability, trading detail for speed, safety and repeatability.
A focused answer to AP CSP Topics 3.15 and 3.16, covering the RANDOM procedure and generating random values, what a simulation is, why simulations are abstractions, their advantages and limitations, and using randomness to model variability, with worked pseudocode.
Sources & how we know this
- AP Computer Science Principles Course and Exam Description — College Board (2025)