Skip to main content
Module 2~8 min

Loops

Loops let a program repeat an action multiple times without writing the same code over and over.

What You'll Learn

  • What a loop is
  • Why loops save repetitive work
  • A basic example of a loop

Repeating Actions

A loop repeats a block of code either a specific number of times or until a certain condition is met, avoiding the need to duplicate the same instructions manually.

A Simple Example

A loop might be used to process every item in a list one at a time, applying the same action to each without writing separate code for each item.

Example

Instead of writing a separate line to print each of ten names, a loop can repeat one print instruction ten times, once for each name in a list.

Key Concepts

LoopRepetitionIteration

Key Takeaways

  • A loop repeats a block of code multiple times
  • Loops avoid the need to duplicate the same instructions manually
  • Loops are often used to process every item in a list

Knowledge Check

What is the main purpose of a loop?

What is the main purpose of a loop?