REPEAT UNTIL(condition) in AP Computer Science Principles

REPEAT UNTIL(condition) is the AP CSP exam reference sheet iteration statement that repeats a block of statements until a Boolean condition evaluates to true; the condition is checked before each pass, so the block runs zero or more times (EK AAP-2.K.3).

Verified for the 2027 AP Computer Science Principles examLast updated June 2026

What is REPEAT UNTIL(condition)?

REPEAT UNTIL(condition) { } is one of the two iteration statements on the AP CSP exam reference sheet. It keeps repeating the block as long as the Boolean condition is false, and it stops the moment the condition evaluates to true. Think of it as "keep going until you're done," where "done" is defined by a Boolean expression instead of a fixed count.

Two details trip people up. First, the condition is the stopping condition, not the keep-going condition. The loop runs while the condition is false, which is backwards from the while loops in most real languages. Second, the condition is checked before each pass through the block. If the condition is already true when the program reaches the loop, the block executes zero times (EK AAP-2.K.1 says iteration repeats statements zero or more times). And if the condition never becomes true, you get an infinite loop (EK AAP-2.K.4).

Why REPEAT UNTIL(condition) matters in AP® Computer Science Principles

This lives in Topic 3.8 (Iteration) in Unit 3: Algorithms and Programming, supporting learning objectives 3.8.A (express an algorithm that uses iteration without a programming language) and 3.8.B (write iteration statements and determine their results or side effects). Iteration is one of the three building blocks of every algorithm, alongside sequencing and selection, and REPEAT UNTIL is the exam's tool for condition-controlled repetition. Because the AP exam uses its own pseudocode, you have to be fluent in exactly this syntax. Tracing a REPEAT UNTIL loop correctly, including the zero-execution case and the infinite-loop case, is one of the highest-frequency MCQ skills in Unit 3.

How REPEAT UNTIL(condition) connects across the course

REPEAT n TIMES (Unit 3)

The other reference-sheet loop. REPEAT n TIMES runs a fixed, known number of times; REPEAT UNTIL runs an unknown number of times that depends on when the condition flips to true. Use n TIMES when you know the count up front, UNTIL when you don't.

Boolean expressions (Unit 3)

The condition inside REPEAT UNTIL is a Boolean expression, the same kind you build with comparison and logic operators in Topics 3.5-3.6. If you misread the Boolean, you misread the whole loop, so these two skills get tested together constantly.

Selection with IF statements (Unit 3)

Selection and iteration both change sequential flow of control using a Boolean condition. The difference is that an IF checks the condition once and moves on, while REPEAT UNTIL keeps checking it before every pass. Spotting which one a question needs is a classic algorithm-design MCQ.

Simulating and traversing lists (Unit 3)

Condition-controlled loops power algorithms where you search until you find something, like scanning a list until a target value appears. Many list-based MCQs wrap a REPEAT UNTIL around an index variable, so you trace both the index update and the stopping condition.

Is REPEAT UNTIL(condition) on the AP® Computer Science Principles exam?

REPEAT UNTIL shows up in multiple-choice questions that ask you to trace pseudocode and determine what a variable equals when the loop ends, how many times the block executes, or what's displayed. Three patterns to drill. One, the zero-execution case, because if the condition is already true before the loop starts, the block never runs (this exact scenario appears in practice questions). Two, the off-by-one trap, where the answer choices differ by a single iteration, so count passes carefully. Three, the infinite loop, where nothing inside the block ever makes the condition true (EK AAP-2.K.4), and the correct answer says the program never terminates. You may also need to pick the loop that correctly implements a described algorithm, which means recognizing when a condition-controlled loop fits better than a counted one.

REPEAT UNTIL(condition) vs REPEAT n TIMES

Both are AP pseudocode loops from the reference sheet, but they're controlled differently. REPEAT n TIMES is count-controlled, so the block runs exactly n times, no condition involved. REPEAT UNTIL(condition) is condition-controlled, so it might run zero times, fifty times, or forever, depending entirely on when the Boolean becomes true. If a question says "repeat for each of the 10 items," think n TIMES; if it says "repeat until the user guesses correctly," think UNTIL.

Key things to remember about REPEAT UNTIL(condition)

  • REPEAT UNTIL(condition) repeats a block of statements until the Boolean condition evaluates to true, meaning the loop runs while the condition is false.

  • The condition is checked before each pass, so if it's already true when the loop is reached, the block executes zero times.

  • If nothing in the block ever makes the condition true, the loop runs forever, which is an infinite loop (EK AAP-2.K.4).

  • REPEAT UNTIL is condition-controlled while REPEAT n TIMES is count-controlled; pick UNTIL when the number of repetitions isn't known in advance.

  • The stopping logic is the reverse of a typical while loop, where a while loop runs while its condition is true but REPEAT UNTIL runs while its condition is false.

  • When tracing these loops on MCQs, track every variable through each pass and double-check the final pass, since off-by-one answers are the most common traps.

Frequently asked questions about REPEAT UNTIL(condition)

What is REPEAT UNTIL(condition) in AP Computer Science Principles?

It's the iteration statement on the AP CSP exam reference sheet that repeats a block of statements until a Boolean condition evaluates to true. It's how the exam's pseudocode expresses condition-controlled loops (EK AAP-2.K.3).

Does REPEAT UNTIL always run at least once?

No. The condition is evaluated before each iteration, so if it's already true when the program reaches the loop, the block executes zero times. EK AAP-2.K.1 explicitly says iteration repeats statements zero or more times, and this zero-execution case is a favorite MCQ trap.

What's the difference between REPEAT UNTIL and REPEAT n TIMES?

REPEAT n TIMES executes the block exactly n times, a fixed count. REPEAT UNTIL executes the block an unknown number of times, stopping only when its Boolean condition becomes true. Use n TIMES for known counts and UNTIL for stop-when-something-happens situations.

Is REPEAT UNTIL the same as a while loop?

Close, but the logic is flipped. A while loop in languages like Python runs while its condition is true; REPEAT UNTIL runs while its condition is false and stops when it becomes true. Both check the condition before each pass, so both can run zero times.

When does REPEAT UNTIL cause an infinite loop?

When the code inside the block never makes the condition true. For example, if the loop waits for a counter to equal 10 but the counter never changes, the condition stays false forever. EK AAP-2.K.4 calls this out, and exam questions sometimes make "the program never terminates" the correct answer.

REPEAT UNTIL(condition) — AP CSP Definition & Exam Guide | Fiveable