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.

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

Updated

In other subjects