# Loops — C Programming Fundamentals: Pointers, Memory and Files

Source: https://www.skillbyai.com/en/c/c-loops

> Repeat code with for, while and do-while loops and control them with break and continue.

## while / do-while / for

`do ... while` runs the body at least once. `for` is best when you know the count.

```c
for (int i = 1; i <= 5; i++) {
    printf("%d ", i);
}
// 1 2 3 4 5
```

Output:

```
1 2 3 4 5
```

## break & continue

`break` exits the loop entirely. `continue` skips to the next iteration.

**Quiz:** Which loop always runs its body at least once?

- [x] do ... while
- [ ] while
- [ ] for
- [ ] switch

*Answer:* do ... while. do ... while checks its condition after the body.
