Skip to main content
United StatesComputer Science PrinciplesSyllabus dot point

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.

Generated by Claude Opus 4.810 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this topic is asking
  2. Arithmetic and the MOD operator
  3. Relational operators
  4. Boolean operators
  5. Try this

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 2 is 0 when n is even, 1 when n is odd.
  • Divisibility. n MOD k = 0 means n is divisible by k.
  • Wrapping/cycling. index MOD length keeps 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 true is true; every other AND is false.
  • false OR false is false; every other OR is true.
  • NOT true is false; NOT false is 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, remainder 23 - 20 = 3. So 23 MOD 4 is 3.

Q2. State the value of NOT (5 < 2) OR (1 > 9). [1 point]

  • Cue. 5 < 2 is false, NOT false is true; 1 > 9 is false; true OR false is 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

Sources & how we know this