Skip to content
S3U
Login Create Account
All video lessons

Science / Grades 4-7

Programming basics: repeat and debug

Learning goal: Trace fixed-count loops, identify the loop body, and debug missing or misplaced actions.

Before you start: Follow drawing instructions in order and count repetitions, including zero.

Read or print this lesson What to practice

Paper Program Studio: session 4

Next: your worksheet

Programming Basics: Repeat a Group of Steps

Continue to worksheet
Not started 0s active

Checking sign-in...

Read the transcript

Video transcript and practice. Reading or printing does not count as playback time or an assessed grade.

1. Write a repeated action once

Video: 0:00

Video illustration: Write a repeated action once. The spoken explanation follows.
Write a repeated action once: video illustration

Sometimes a program needs to do the same action several times. A loop lets us describe that repetition. Our plan repeats one drawing action three times, then performs a different action afterward. The key is knowing which instructions belong inside the loop.

2. Find the loop body

Video: 0:20

Video illustration: Find the loop body. The spoken explanation follows.
Find the loop body: video illustration

Read the instruction repeat three times, then look at its body: draw dot. Each repetition draws one dot. The word end marks where the repeated body finishes. It is a boundary in our teaching notation, not another drawing action.

3. Count the repetitions

Video: 0:39

Video illustration: Count the repetitions. The spoken explanation follows.
Count the repetitions: video illustration

Trace each pass. After the first pass there is one dot. After the second there are two. After the third there are three. The program does not need three copies of the draw instruction; it uses the same instruction on each pass.

4. Continue after the loop

Video: 0:58

Video illustration: Continue after the loop. The spoken explanation follows.
Continue after the loop: video illustration

After the end marker, the program says draw line. That instruction is outside the repeated body, so it happens once after the three dots. The line did not buy a ticket for the repeat ride. Its position in the plan matters.

5. Pause and change the count

Video: 1:16

Video illustration: Pause and change the count. The spoken explanation follows.
Pause and change the count: video illustration

Change only the repeat count from three to four. Leave the dot inside the loop and the line after it. Pause and predict both the number of dots and the number of lines. Do not multiply every instruction just because the program contains a loop.

6. Check the two counts

Video: 1:36

Video illustration: Check the two counts. The spoken explanation follows.
Check the two counts: video illustration

The revised plan makes four dots and still just one line. Only the loop body repeats. If we wanted a line on every pass, its instruction would need to move inside that body. A careful trace can catch a misplaced instruction.

7. Zero can be a useful count

Video: 1:55

Video illustration: Zero can be a useful count. The spoken explanation follows.
Zero can be a useful count: video illustration

Fun fact: repeating a body zero times can be perfectly meaningful. The body is skipped, but instructions after the loop still run. In our example, a repeat count of zero gives no dots and one line. Zero does not mean erase the whole program.

8. Predict, check, and improve

Video: 2:15

Video illustration: Predict, check, and improve. The spoken explanation follows.
Predict, check, and improve: video illustration

Debugging means finding and fixing mistakes in a program. Compare the intended result with the traced result, change one thing, and check again. Continue to the worksheet to practice loop boundaries and zero repetitions. No downloads or code execution are needed for this practice.

Show your understanding

You can point, explain aloud, draw or write.

  • Identify the repeated body and trace the requested number of passes.
  • Keep an instruction after the loop separate, and check what happens when the repeat count is zero.

Try it yourself

Pause and trace the instructions before checking the answer.

Continue to the matching worksheet. These examples use teaching pseudocode, not code to paste into a computer.

Next: your worksheet

Programming Basics: Repeat a Group of Steps

https://s3u.com/sc570

Lesson: https://s3u.com/lessons/programming-loops