Skip to content
BENIBIX Learn

Loop

Development🧩 Programming ConceptsControl Flow

Code that runs the same lines again and again. It goes until told to stop.

Think of it like

Think of it like running laps of a track. You go round and round until the coach says stop.

Example

A shop's app loops over 500 orders in its list. For each one, it adds the price to the day's total.

Why it matters

Computers are good at doing the same thing many times. Loops are how you ask them to.

Definition

A loop runs the same lines of code again and again. Each time round is called one pass. A loop can repeat once for each item in a list, or keep going while a test stays true. Something has to end it, or it runs forever. Loops let a few lines of code handle a million items.

Common mistake

Copying the same lines ten times instead of writing one loop. A change then has to be made ten times.

Key takeaways

  1. 1
    Repeat the same lines. One block runs many times.
  2. 2
    Needs an end. A list runs out, or a test turns false.
  3. 3
    Scales up. Ten items or ten million, same code.

Learn it properly