AP CSP Day 26: Data Correlation

Big Idea 3: Algorithms & Programming
Cycle 1 • Day 26 Practice • Medium Difficulty
Focus: Iteration Patterns

Practice Question

What is displayed after the following code runs?

i ← 1
REPEAT UNTIL i > 5
{
   IF i MOD 2 = 0
   {
      DISPLAY(i)
   }
   i ← i + 1
}
Why This Answer?

The loop runs for i = 1, 2, 3, 4, 5 (stops when i > 5). The IF condition checks whether i is even (i MOD 2 = 0). Even values are 2 and 4, so those are displayed.

Why Not the Others?

A) 1, 3, 5 are odd numbers where MOD 2 = 1, not 0. They fail the condition. B) Not all values are displayed — only those passing the MOD 2 = 0 filter. D) The loop stops when i exceeds 5, so i = 6 is never processed inside the loop body.

Common Mistake
Watch Out!

Students confuse MOD 2 = 0 (even numbers) with MOD 2 = 1 (odd numbers), or they forget that the loop condition is checked before each iteration.

AP Exam Tip

MOD 2 = 0 means even. MOD 2 = 1 means odd. Write this down as a reference during the exam to avoid mixing them up.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.