# Loops

Do the same thing to every file, every line, or until something is true.

Updated: November 10, 2026

## [Repeating](https://www.ask-codey.com/courses/bash-in-depth/topics/bash-repeating)

1. [For Every File: for Loops](https://www.ask-codey.com/lessons/bash-for-loops) (Apprentice): A for loop runs the same commands once for every word, number or file in a list, so renaming 12 files or 200 takes one line, with ${f%.tmp} cutting the old ending off each name.
2. [Line by Line: while read](https://www.ask-codey.com/lessons/bash-while-read) (Journeyman): while IFS= read -r line reads a file one whole line at a time, spaces and backslashes kept, and while and until repeat commands for as long as a condition is true, or until it becomes true.
3. [Stopping Early: break, continue and Counters](https://www.ask-codey.com/lessons/bash-loop-control) (Apprentice): A counter or running total is a variable a loop adds to each time round with $(( )); continue skips the rest of one pass and goes on with the next item, and break leaves the loop early.

## [Exercise: Rename the Telemetry](https://www.ask-codey.com/courses/bash-in-depth/topics/exercise-bash-rename-the-telemetry)

1. [Exercise: Rename the Telemetry](https://www.ask-codey.com/lessons/exercise-bash-rename-the-telemetry) (Apprentice): Write two small tools for Mission Control, a script that renames every .tmp file in a folder and one that pulls the warnings out of a flight log, then run them on the real files and let a check script tell you what's done.

Source: https://www.ask-codey.com/courses/bash-in-depth/chapters/bash-loops
