# 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 items or add up a total.

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

A **loop counter** is a variable you start at 0 before a loop and add to inside it, like a tally on scrap paper. `$count++` adds one, and `$total += $minutes` keeps a running total. Set inside the loop, it would go back to 0 on every pass.

```powershell
$count = 0
$total = 0
foreach ($song in Import-Csv playlist.csv) {
    $count++
    $total += [int]$song.Minutes
}
"$count songs, $total minutes"
# 6 songs, 29 minutes
```

## In a sentence

- “The rename script keeps a **loop counter** and ends with Files renamed: 30.”
- “Sam started his **loop counter** at 0 before the loop, not inside it.”

Level: Apprentice · [More PowerShell terms at this level](https://www.ask-codey.com/glossary?category=powershell&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 Unix](https://www.ask-codey.com/glossary/loop-counter-unix)

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