Pseudocode Core Structures (Cambridge Standard): REPEAT UNTIL Loops And Logical Reversal Traps (Copy)
REPEAT UNTIL Loops And Logical Reversal Traps (Cambridge Standard – O Level 2210 + IGCSE 0478)
Purpose Of REPEAT UNTIL Loops In Cambridge Pseudocode
- REPEAT UNTIL loops are used when:
- A block of statements must execute at least once
- Cambridge uses REPEAT UNTIL sparingly to test:
- Understanding of post-test loops
- Correct logical conditions
- Ability to avoid logical reversal errors
- REPEAT UNTIL commonly appears in:
- Menu-driven programs
- Input validation where first input must occur before checking
- Controlled repetition that must run once
Core REPEAT UNTIL Structure (Cambridge Standard)
- REPEAT
- statements
- UNTIL condition
Execution Rule (Examiner-Critical)
- The loop body:
- Executes first
- The condition is checked:
- After the loop body
- The loop continues:
- While the condition is FALSE
- The loop stops:
- When the condition becomes TRUE
Key Difference From WHILE Loops
| REPEAT UNTIL | WHILE |
|---|---|
| Post-test loop | Pre-test loop |
| Runs at least once | May run zero times |
| Condition checked at end | Condition checked at start |
| Stops when condition TRUE | Stops when condition FALSE |
- This difference is a major examiner focus
Correct Interpretation Of UNTIL Condition
- UNTIL condition means:
- “Stop when this condition becomes TRUE”
- Do NOT treat UNTIL like WHILE
Correct understanding:
- REPEAT
- INPUT value
- UNTIL value >= 0 AND value <= 100
- Stops when value is valid
Logical Reversal Trap (Most Common Exam Error)
The Core Trap
- Students write:
- The invalid condition in UNTIL
- This reverses logic and causes:
- Premature termination
- Or infinite looping
Incorrect Example (Logical Reversal)
- REPEAT
- INPUT score
- UNTIL score < 0 OR score > 100
Why it is wrong:
- Loop stops when input is invalid
- Opposite of requirement
Correct Example
- REPEAT
- INPUT score
- UNTIL score >= 0 AND score <= 100
- Condition represents:
- The exit condition, not the looping condition
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
REPEAT UNTIL And Input Validation (Correct Pattern)
Standard Validation Pattern
- REPEAT
- INPUT value
- IF value < min OR value > max THEN
- OUTPUT “Invalid input”
- ENDIF
- UNTIL value >= min AND value <= max
Examiner Expectations
- INPUT must occur:
- Inside the loop
- Validation message:
- Optional but rewarded if present
- Condition:
- Must represent valid state
REPEAT UNTIL And Menu Systems
Menu Loop Pattern
- REPEAT
- OUTPUT “1. Add”
- OUTPUT “2. Delete”
- OUTPUT “0. Exit”
- INPUT choice
- UNTIL choice = 0
Examiner Checks
- Menu displayed at least once
- Exit condition:
- Clearly stated
- Choice evaluated after display
REPEAT UNTIL And Sentinel Values
- REPEAT
- INPUT value
- PROCESS value
- UNTIL value = sentinel
Examiner Warning
- Sentinel value:
- May be processed once
- This is acceptable only if the question allows it
- If sentinel must not be processed:
- WHILE loop is safer
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Condition Construction Rules For REPEAT UNTIL
Rule 1: Write Exit Condition, Not Loop Condition
- Think:
- “When should this stop?”
- Not:
- “When should this continue?”
Rule 2: Avoid NOT Where Possible
- NOT increases reversal risk
Risky:
- UNTIL NOT valid
Safer:
- UNTIL valid
Rule 3: Use Brackets For Compound Conditions
- Especially with AND / OR
Correct:
- UNTIL (score >= 0 AND score <= 100)
Common Logical Reversal Errors
Error 1: Using Same Condition As WHILE
- Students convert WHILE directly to REPEAT UNTIL
- Without reversing condition
- This breaks logic
Error 2: Double Negatives
- UNTIL NOT (score < 0 OR score > 100)
- Hard to trace
- High error probability
Error 3: Reversed AND / OR
- Using OR instead of AND in exit condition
- Produces early termination
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
REPEAT UNTIL And Trace Tables
Trace Table Behaviour
- First iteration:
- Always executes
- Condition check:
- Happens after loop body
- Trace tables must include:
- At least one execution
Common Trace Errors
- Assuming condition checked before first iteration
- Missing final terminating check
- Treating UNTIL like WHILE
REPEAT UNTIL In Section B Modifications
- Section B may ask:
- Replace WHILE with REPEAT UNTIL
- Or adjust termination logic
- Correct approach:
- Reverse the condition
- Do not reuse same condition
Safe Conversion Example
Original WHILE:
- WHILE value < min OR value > max DO
- INPUT value
- ENDWHILE
Converted REPEAT UNTIL:
- REPEAT
- INPUT value
- UNTIL value >= min AND value <= max
When NOT To Use REPEAT UNTIL
- When:
- Input must be validated before processing
- Sentinel must not be processed
- Loop may legitimately run zero times
- In these cases:
- WHILE is safer and preferred
Illegal REPEAT UNTIL Practices (Guaranteed Mark Loss)
- Using continuation condition instead of exit condition
- Missing UNTIL
- Writing UNTIL inside loop body
- Using uninitialised variables in condition
- Confusing UNTIL with WHILE
Best-Practice REPEAT UNTIL Strategy For Paper 2
- Use only when at-least-once execution is required
- Always write the exit condition
- Avoid NOT where possible
- Bracket compound conditions
- Trace once manually to confirm logic
Final Quality Checklist
- Loop body executes at least once
- UNTIL condition represents stopping condition
- No logical reversal
- Variables in condition are updated inside loop
- Condition is traceable and clear
Final Lock-In Rules
- REPEAT UNTIL is post-test
- Condition means “stop when TRUE”
- Logical reversal is the biggest trap
- REPEAT UNTIL is less common but heavily punished if wrong
- Clear exit conditions = safe Paper 2 marks
