A loop runs the same block of code once per item, updating its variables each time through. Below is a real widget from epochai's own curriculum, not a diagram.
A for loop takes a collection — a list, a range of numbers — and runs its body once for each
item in it. Each pass, the loop variable (often called n, i, or whatever name
fits) gets set to the next item, and any code inside the loop runs again with that new value.
The part worth watching closely is an accumulator: a variable declared before the loop starts,
that the loop body updates on every pass. total = 0 followed by total += n inside
the loop is the classic pattern — by the time the loop ends, total holds the sum of everything
it saw, one small update at a time.
This is also where most beginner bugs live: forgetting to initialize the accumulator before the loop, or updating the wrong variable inside it. Tracing the loop step by step — which is exactly what the widget below does — is the fastest way to see where a loop's logic actually breaks.
Module 1 — Programming Fundamentals — covers variables, control flow, loops, functions, and debugging. Free, no card required.