Iteration FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

(a) How many times does the body run in REPEAT 6 TIMES { n ← n + 1 } if n starts at 0? Final n? (b) Reset n to 0. For REPEAT UNTIL (n = 6) { n ← n + 1 }, how many body runs? (c) Off-by-one risk if the UNTIL condition becomes (n > 6) instead of (n = 6)?

Question 2 of 5

p starts at 3. REPEAT UNTIL (p >= 3) { p ← p + 1 DISPLAY (p) } (a) How many times does the body execute? Justify using the initial value. (b) Change only the initial p so the body runs exactly once. Give initial p and the displayed value. (c) What happens if the ending condition can never become true?

Question 3 of 5

Student wants 5,6,7 displayed: m ← 5 REPEAT UNTIL (m > 7) { DISPLAY (m) m ← m + 1 } (a) Trace the displays. (b) If condition is mistakenly (m >= 7), what is displayed? (c) Write REPEAT n TIMES that displays 5,6,7 from m ← 5.

Question 4 of 5

Robot R faces east. W = wall.

Row Col1 Col2 Col3
Row1 W W
Row2 W R W
Row3 W W W

(a) Moves/turns to reach the open cell north without hitting a wall. (b) Write a short REPEAT segment for those actions. (c) Why is REPEAT UNTIL (NOT CAN_MOVE(forward)) risky if the robot faces wrong first?

Question 5 of 5

score starts at 10. (a) Trace REPEAT UNTIL (score <= 0) { score ← score - 4 DISPLAY (score) }. List displayed values. (b) How many body executions? (c) Does changing to (score < 0) add another displayed value for step size 4? Justify.