Unit 3 · Programming 2 · Lesson 3.2

The Flip: while vs REPEAT UNTIL

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.

Big Idea 3 — Algorithms & ProgrammingFlip drill — weekly until May

Before this lesson — read on Runestone

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.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

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.

2

The Hook

Same countdown. Opposite words. “Keep going while there’s time left.” “Keep going until time runs out.” Both describe the identical behavior — but one states the continue condition and the other states the stop condition, and they are exact opposites.

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.

3

The Idea

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 > 0REPEAT UNTIL (n ≤ 0)
while x < 10REPEAT UNTIL (x ≥ 10)
while guess != secretREPEAT UNTIL (guess = secret)
Negation flips each operator to its opposite: >↔≤, <↔≥, ==↔!=. “Loop while more than zero” is the same as “loop until zero or less.”

Python — while

n = 3
while n > 0:
    print(n)
    n = n - 1

AP Pseudocode — REPEAT UNTIL

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.

Compound conditions flip too — and the connector changes. This is 2.14’s De Morgan intuition doing real work: 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.
4

Try It — The Flip Translator

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
Python:  while n > 0
AP:  press "Show the flip"
5

Vocabulary

negation Programs
Flipping a condition to its opposite — what you do to translate between while and REPEAT UNTIL.
REPEAT UNTIL Programs
AP Pseudocode’s condition-controlled loop. It repeats until its condition becomes true — that is, while the condition is false.
6

Check

Five flips and traces. Negate carefully — each operator flips, and and/or swap. Then pick your answer.

0 of 5 answered
7

Impact Check

Two ways to say the same rule — and why it matters

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.

8

Connections

Came from 3.1 — the same countdown loop, now written the exam’s way.
Uses 2.14 — negating a compound condition is De Morgan’s intuition: and becomes or.
Next in 3.3 — when you know exactly how many times to repeat, a counting loop (for) is cleaner than a while.
Returns on the exam — REPEAT UNTIL traces and while/until negation are among the two most-missed mechanical items. This drill returns weekly for a reason.
← 3.1 The while Loop