Boolean Logic, Relational Operators, MOD

In CSP pseudocode.

What to practice

  • Evaluate arithmetic expressions using +, -, *, /, and a MOD b.
  • Evaluate compound boolean expressions with =, !=, >, <, >=, <=, NOT, AND, and OR.
  • Determine whether two conditional algorithms produce identical results for all possible inputs.

1. Core Concept Instruction

In AP CSP pseudocode, the modulus operator a MOD b evaluates to the remainder when non-negative integer a is divided by positive integer b (e.g., 17 MOD 5 = 2, 20 MOD 5 = 0, and 3 MOD 8 = 3). The condition (n MOD 2 = 0) tests whether n is even, (n MOD 2 = 1) tests whether n is odd, and (n MOD k = 0) tests whether n is a multiple of k. Selection statements use IF(condition) { /* body / } ELSE { / body */ }. Pay close attention to the difference between a chain of independent IF statements vs. an IF / ELSE IF / ELSE structure: in a sequence of separate IF statements, multiple branches can execute in the same pass if multiple conditions are true (or if an earlier IF modifies the variable tested by a later IF!).

2. Worked Examples

Worked Sequential IF vs. Nested IF/ELSE Comparison

Suppose score <- 85. Compare the final value of grade in Segment I (sequential IFs) vs. Segment II (nested IF/ELSE):
Segment I:
IF (score >= 70) { grade <- "C"; score <- score - 20 }
IF (score >= 80) { grade <- "B" } ELSE { grade <- "D" }
Segment II:
IF (score >= 80) { grade <- "B" } ELSE { IF (score >= 70) { grade <- "C" } ELSE { grade <- "D" } }

Result:

De Morgan's Law in AP Pseudocode & Nested Conditional Equivalences

Determine which Boolean expression is logically equivalent to:
NOT ((temp < 32) OR (humidity >= 80))

Result: (temp >= 32) AND (humidity < 80)

Core Concept Review

In AP CSP pseudocode, the modulus operator a MOD b evaluates to the remainder when non-negative integer a is divided by positive integer b (e.g., 17 MOD 5 = 2, 20 MOD 5 = 0, and 3 MOD 8 = 3). The condition (n MOD 2 = 0) tests whether n is even, (n MOD 2 = 1) tests whether n is odd, and (n MOD k = 0) tests whether n is a multiple of k. Selection statements use IF(condition) { /* body / } ELSE { / body */ }. Pay close attention to the difference between a chain of independent IF statements vs. an IF / ELSE IF / ELSE structure: in a sequence of separate IF statements, multiple branches can execute in the same pass if multiple conditions are true (or if an earlier IF modifies the variable tested by a later IF!).

Extended Concept Analysis

In AP CSP pseudocode, the modulus operator a MOD b evaluates to the remainder when non-negative integer a is divided by positive integer b (e.g., 17 MOD 5 = 2, 20 MOD 5 = 0, and 3 MOD 8 = 3). The condition (n MOD 2 = 0) tests whether n is even, (n MOD 2 = 1) tests whether n is odd, and (n MOD k = 0) tests whether n is a multiple of k. Selection statements use IF(condition) { /* body / } ELSE { / body */ }. Pay close attention to the difference between a chain of independent IF statements vs. an IF / ELSE IF / ELSE structure: in a sequence of separate IF statements, multiple branches can execute in the same pass if multiple conditions are true (or if an earlier IF modifies the variable tested by a later IF!).

Worked Problem Walkthrough

Worked Sequential IF vs. Nested IF/ELSE Comparison

Suppose score <- 85. Compare the final value of grade in Segment I (sequential IFs) vs. Segment II (nested IF/ELSE): Segment I: IF (score >= 70) { grade <- "C"; score <- score - 20 } IF (score >= 80) { grade <- "B" } ELSE { grade <- "D" } Segment II: IF (score >= 80) { grade <- "B" } ELSE { IF (score >= 70) { grade <- "C" } ELSE { grade <- "D" } }

De Morgan's Law in AP Pseudocode & Nested Conditional Equivalences

Determine which Boolean expression is logically equivalent to: NOT ((temp < 32) OR (humidity >= 80))

Common Exam Traps & How to Avoid Them

  • Assuming that two separate IF statements behave like an IF / ELSE IF chain when their conditions overlap.

  • Thinking that 4 MOD 10 is 2.5 or 2 instead of 4 (when a < b for non-negative a, a MOD b is always a).

Key Vocabulary

  • MOD Operator: The remainder operator a MOD b, returning the remainder when a is divided by b.

  • Selection: An algorithmic structure (IF / ELSE) that uses a boolean condition to determine which code segment to execute.

Use this chapter companion

Review the lesson, attempt the original practice, then check the explanation. Your printed study guide remains complete without the website.

Independence

Skill by Skill Prep is independent. SAT® and AP® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website or book. PSAT/NMSQT® is a registered trademark of the College Board and the National Merit Scholarship Corporation, which are not affiliated with, and do not endorse, this site. Bluebook™ is a trademark of the College Board. ACT® is a trademark of ACT Education Corp., which is not affiliated with and does not endorse this website or book. Desmos is a trademark of Desmos Studio PBC. Practice results describe these questions, not official scores or admission predictions.

Last updated .