Unable to open this exercise
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.
Independent Practice: Limited attempts
Allow at most three integer PIN attempts. The correct PIN is 2468. Stop immediately on success and output ACCESS; otherwise output DENIED after three wrong attempts.
Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.
Interactive exercises for Module 2 and beyond require an active plan.
Run code to inspect step-by-step variable trace states.