# Loops in Bash — Linux

Source: https://www.geekswithgeeks.com/en/linux/linux-bash-loops

> for and while loops for repetitive tasks.

## for loop

Iterate over a list of values or files.

```bash
for f in *.txt; do
    echo "Found: $f"
done
```

Output:

```
Found: notes.txt
Found: todo.txt
```

## while loop

Runs as long as its condition stays true.

```bash
count=1
while [ $count -le 3 ]; do
    echo "count: $count"
    count=$((count + 1))
done
```

Output:

```
count: 1
count: 2
count: 3
```

**Quiz:** In `[ $count -le 3 ]`, what does `-le` mean?

- [ ] less than
- [x] less than or equal to
- [ ] not equal

*Answer:* less than or equal to. `-le` is bash's numeric "less than or equal to" test operator.
