Question 1 of 5
(a) t starts at 0: REPEAT 5 TIMES { t ← t + 1 }. Final t? (b) Reset t to 0: REPEAT UNTIL (t > 5) { t ← t + 1 }. Final t and iterations? (c) Off-by-one difference between (t = 5) and (t > 5) when incrementing by 1 from 0?
Responses receive AI feedback against a rubric after submission. Scores are practice estimates.
(a) t starts at 0: REPEAT 5 TIMES { t ← t + 1 }. Final t? (b) Reset t to 0: REPEAT UNTIL (t > 5) { t ← t + 1 }. Final t and iterations? (c) Off-by-one difference between (t = 5) and (t > 5) when incrementing by 1 from 0?
volume starts at 8. REPEAT UNTIL (volume = 0) { volume ← volume - 2 DISPLAY (volume) } (a) Displayed values? (b) Why does it stop? (c) If volume started at 9 with step -2, explain the infinite-loop risk.
P: n ← 1 REPEAT 3 TIMES { DISPLAY (n) n ← n + 1 } Q: n ← 1 REPEAT UNTIL (n >= 3) { DISPLAY (n) n ← n + 1 } (a) P displays? (b) Q displays? (c) Fix Q's UNTIL condition to match P.
Robot faces north at R. W = wall.
| Row | C1 | C2 | C3 |
|---|---|---|---|
| R1 | W | W | W |
| R2 | W | R | |
| R3 | W | W | W |
(a) Using REPEAT plus MOVE_FORWARD / ROTATE_RIGHT, move to C3 of R2. (b) How many MOVE_FORWARD executions? (c) If REPEAT UNTIL (NOT CAN_MOVE(forward)) runs before turning, what goes wrong?
c starts at 1. (a) Trace REPEAT UNTIL (c > 1) { c ← c + 1 }. Final c and iterations? (b) Trace REPEAT UNTIL (c >= 1) { c ← c + 1 }. Final c and iterations? (c) Relate answers to checking UNTIL before the body.