# For Loop

> A loop that runs once for each item in a list, then stops by itself.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** for

## Think of it like

Think of it like a teacher reading the names in class. Each name is called once, in order.

## Definition

A for loop runs its lines once for each item in a list or a range. Each time round, a variable holds the next item. When the items run out, the loop ends by itself. Python writes it as for name in names. Other languages, like C and JavaScript, often count with a number instead.

## Example

A class app runs a for loop over 28 names. It sends each pupil the same reminder about the school trip.

## Example code

```python
for name in ["Emma", "Jack"]:
    print("Hi", name)
# Hi Emma
# Hi Jack
```

Two names, so the loop runs twice and then stops.

## Why it matters

Most loops go over a list of things. A for loop does that and can never forget to stop.

## Common mistake

Changing the list while looping over it. Items get skipped or seen twice.

## Three principles

- **Once per item.** Each item gets exactly one pass.
- **Ends by itself.** No items left means no more passes.
- **A name for the item.** A variable holds the current one.

## Related terms

- [Loop](https://learn.benibix.com/term/development/loop)
- [While Loop](https://learn.benibix.com/term/development/while-loop)
- [Array](https://learn.benibix.com/term/development/array)
- [Break Statement](https://learn.benibix.com/term/development/break-statement)
- [Iterator](https://learn.benibix.com/term/development/iterator)

## Told apart from

- [For Loop vs While Loop](https://learn.benibix.com/compare/for-loop-vs-while-loop): A for loop goes over a list and stops when the list runs out. A while loop goes on until its test turns false.

## Taught in

- [For and While Loops](https://learn.benibix.com/learn/development-concepts/for-and-while-loops): Programming Basics, 11/18

---

Source: https://learn.benibix.com/term/development/for-loop
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
