# Loop Counter

*noun*

say it: **“LOOP KOWN-ter”** **/ˈlup ˈkaʊntər/**

A variable that goes up by one, or by an amount, each time a loop goes round, to count or add things up.

## What is a **loop counter** in bash?

A **loop counter** is a variable a loop adds to each time round, like a tally on a scorecard. Set it to 0 before the loop, add to it inside with `$(( ))`, and read it after `done`. A second one can keep a running total.

```bash
count=0
for f in telemetry/*.log; do
  count=$(( count + 1 ))
done
echo "$count files"
```

## In a sentence

- “Sam started his **loop counter** at 0, before the loop began.”
- “The **loop counter** said twelve songs fit on the drive.”

Level: Apprentice · [More Unix terms at this level](https://www.ask-codey.com/glossary?category=unix&level=2)

Updated: November 10, 2026

## In other subjects

- [Loop Counter in C#](https://www.ask-codey.com/glossary/loop-counter-c-sharp)
- [Loop Counter in Java](https://www.ask-codey.com/glossary/loop-counter)
- [Loop Counter in JavaScript](https://www.ask-codey.com/glossary/loop-counter-javascript)
- [Loop Counter in PowerShell](https://www.ask-codey.com/glossary/loop-counter-powershell)

Source: https://www.ask-codey.com/glossary/loop-counter-unix
