Unable to open this exercise
Common exam pitfall
Students often write the continuation condition rather than the exit condition after UNTIL.
In computer programming, when an action must occur before a condition can be tested (such as prompting a user for input), developers use a Post-Condition Loop (REPEAT ... UNTIL).
1. Syntax of REPEAT ... UNTIL
REPEAT
// Statements executed at least once
UNTIL <TerminationCondition>
The Two Critical Behaviors:
- Guaranteed Execution: Because the condition is located at the bottom of the structure, the loop body is guaranteed to run at least once.
- Termination Logic: The loop continues executing as long as the condition is
FALSE. The moment the condition evaluates toTRUE, the loop terminates immediately.
2. Crucial Comparison: REPEAT ... UNTIL vs WHILE ... DO
Feature |
|
|
|---|---|---|
Condition Location | Evaluated at the bottom after loop body. | Evaluated at the top before loop body. |
Minimum Iterations | 1 (Always runs at least once). | 0 (May never run if condition is initially false). |
Exit Condition | Loops while | Loops while |
Typical Use Case | User input validation, menu prompts, retry limits. | Searching arrays, reading file data until EOF. |
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Exam-Style Question: Complete Post-Condition Validation Loop
Complete the keywords in this post-condition input loop ensuring a positive number greater than 0 is entered:
[Space 1]
OUTPUT "Enter positive number: "
INPUT Number
[Space 2] Number [Space 3] 0
Interactive exercises for Module 2 and beyond require an active plan.