AP CSP Day 26: Data Correlation
Share
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
}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.
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.
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.
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