The question to explore

Make a short playlist

How does a program repeat an action and stop?

About 7 minutes / Suggested pace / No account needed

  • Loop
  • Iteration
  • Stopping condition
Try the experiment

What this activity helps you do

Choose the playlist length and count the additions. A loop repeats a step until it reaches a limit. AI helpers that repeat searches or edits need a stopping rule too.

Local teaching illustration / No AI model call

  1. Choose 5 in How many songs? Predict how many additions you will see.
  2. Read the repeated instruction for each song. Notice that the last one adds song 5.
  3. Change the count to 1, then 8. The same rule builds a different length of playlist.
Add song 1 to the playlist
Add song 2 to the playlist
Add song 3 to the playlist

Change a control to explore the example when JavaScript is enabled.

The idea

To make five playlist entries, repeat “add the next song” five times. Each repeat is an iteration. Your chosen count tells the loop when to stop.

Try one, five and eight entries. The instruction stays the same; the number of repeats changes. This is a local illustration. It does not play music or contact a music service.

Take this with you

What changed?

A loop repeats a step until its stopping condition is met.

Try explaining it.

What if the program keeps adding songs without checking your chosen count?

Open a possible explanation

It would not know when to stop. A count or another clear limit keeps repeated work under control. AI tool loops need limits too.

Choose what to try next

Keep exploring, or stay here and try another variation.

By Jonathan Simone, with AI assistance. First edition, October 2026. Activities are fictional teaching examples, not measured AI performance. Help us improve this lesson.

An optional completion mark and your explanation preference can be saved to this browser. Exercise entries stay in this page unless you choose to download a file. View or clear your check-ins.