How Logic Works

For Loop

A loop that runs a specific number of times, usually iterating over a collection of items.

Definition

A loop that runs a specific number of times, usually iterating over a collection of items. It's the most common type of loop and is used whenever you need to do something to each item in a list.

Example

for i in range(5): print(i) — this prints the numbers 0, 1, 2, 3, 4. The loop runs exactly five times.

See it in context Learn how For Loop fits into the bigger picture of how software actually works.

Read the Guide →