Python loops while a condition is true. AP Pseudocode loops until a condition is true. Same loop, opposite conditions — and this exact flip is one of the two most-missed ideas on the whole exam.
Same page as 3.1 — today we compare Python’s while to the
exam’s REPEAT UNTIL. Enrolled in our Runestone course? Open it from there so your
progress counts.
Still in Programs. You know the while loop from 3.1.
The exam almost never writes Python while — it writes REPEAT UNTIL,
whose condition is the opposite. Reading that correctly is worth real points, and it
trips up more students than almost anything else.
Python and AP Pseudocode made opposite choices.
while keeps looping while its condition is true.
REPEAT UNTIL keeps looping until its condition becomes true —
i.e., while it’s false. Miss the flip and you’ll trace the loop backwards.
To translate a loop between the two, you negate the condition — flip it to its opposite:
Python while (loop while true) | AP REPEAT UNTIL (loop until true) |
|---|---|
| while n > 0 | REPEAT UNTIL (n ≤ 0) |
| while x < 10 | REPEAT UNTIL (x ≥ 10) |
| while guess != secret | REPEAT UNTIL (guess = secret) |
>↔≤,
<↔≥, ==↔!=. “Loop
while more than zero” is the same as “loop until zero or less.”
n = 3 while n > 0: print(n) n = n - 1
n ← 3 REPEAT UNTIL (n ≤ 0) { DISPLAY(n) n ← n - 1 }
Hover or tap a line to light its twin. Both print 3, 2, 1. Line 2 is
the whole lesson: n > 0 (keep going) becomes n ≤ 0 (stop) — the
exact opposite.
while (a > 0 and b > 0) becomes
REPEAT UNTIL (a ≤ 0 OR b ≤ 0). When you negate an and, it turns
into an or (and vice versa), and each comparison flips. Miss the
and→or switch and the loop stops at the wrong time.
Pick a Python while condition. The translator shows the matching
REPEAT UNTIL condition — its exact opposite. Try to say the flip before you reveal
it.
while and REPEAT UNTIL.Five flips and traces. Negate carefully — each operator flips, and and/or
swap. Then pick your answer.
Continue-conditions and stop-conditions are two honest ways to describe one behavior, and different languages, standards, and even everyday instructions pick different ones. “Stay on the highway until exit 12” and “stay on the highway while you haven’t reached exit 12” mean the same drive.
The exam tests this because getting a negation backwards is a real,
expensive bug: a loop that stops one step too early or too late, a check that lets the wrong case
through. Being able to flip a condition cleanly — and knowing and becomes
or when you do — is a genuine professional skill, not just an exam trick.
and becomes or.for) is cleaner than a while.REPEAT UNTIL traces and while/until negation
are among the two most-missed mechanical items. This drill returns weekly for a reason.