← Back to course
Intro to CS 9-10 / Week 04 / Mission Quest
6/6
Week 04 · Loops

Mission Quest

Mission Quest: The Human Loop
// Doing a job many times, and knowing when to stop
⏱ about 20 min

Mission Quest: The Human Loop

The greenhouse lights dim for the evening, and the crew gathers around the work table.

Comet writes a big card that says REPEAT UNTIL. "New game," she announces. "One of us is the computer."

"The computer may only do exactly what the card says," Wren adds. "No guessing, no shortcuts."

Nova hovers above the table and projects a blank trace table. "Someone has to keep the trace," she says.

"That is the most important job in the room."

Comet volunteers to be the computer. Wren picks up the pencil with a grin.

  1. Every algorithm can be built from sequencing, selection and iteration.
  2. REPEAT n TIMES runs the loop body a set number of times.
  3. REPEAT UNTIL checks its condition first. If the condition starts true, the body never runs.
  4. If the ending condition can never become true, the loop is infinite.
  5. A trace table shows every value after every pass. It is one of the best ways to find errors.
  6. Choose a loop by the job, and explain your choice for readability and correctness.
◇ THE HUMAN LOOP
You need paper, a pencil, and ten small objects such as spoons or socks.
One player is the computer. One player keeps the trace table. Anyone else writes the loop cards. With only two players, write the cards together first.
Write a loop card, such as: count gets 0. REPEAT UNTIL count is at least 6: add 2 to count and stack one object.
The computer follows the card exactly, out loud. The tracer writes count after every pass.
Now try a broken card, where count goes up by 2 and stops only when count equals 5.
Stop the broken loop after five passes. Talk about why it would never end, then fix the card together.
Swap jobs and play again with new cards.
For a grown-up
This week your student learned loops: the part of a program that repeats.
Ask: what is one job at home that repeats a set number of times, and one that repeats until something happens?
Ask: why would a programmer test a program carefully before sharing it with many people?
Everything in this course is done on paper. No app, website or account is needed.
QUEST CHECK
  • Read the question.
  • Tap your answer.
A card says: count gets 0, then REPEAT UNTIL count is at least 6, adding 2 each pass. How many passes?
A card stops only when count equals 5, but count goes 2, 4, 6, 8. What kind of loop is it?
Which job in the game is most like hand tracing?
Quest reviewTrue or false?
In the game, the computer may only do what the card says.?
A loop card that skips over its stop value can run forever.?
The tracer can skip writing values when the numbers get boring.?
WHY THIS EXERCISEA computer follows instructions exactly, so a complete trace is how we see what it really does.
← Friday