Bash Conditionals, Loops, and Functions/C-style arithmetic for loop

Use arithmetic syntax in Bash for loops.

Section: Loops

C-style arithmetic for loop

bash
bash
for ((i=0; i<5; i++)); do echo "$i"; done
Explanation

Helpful for counters and indexed arrays.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Loops
For loop over words
Iterate over a list or glob.
OpenIn sheetbashsame section
While read loop
Read input line by line safely.
OpenIn sheetbashsame section
Until loop
Run loop until command succeeds.
OpenIn sheetbashsame section
Use break and continue
Skip or exit loop iterations.
OpenIn sheetbashsame section
Simple select menu
Create a numbered shell menu.
OpenIn sheetbashsame section
Compare integers
Use arithmetic context for integer comparisons.
OpenIn sheetbash1 tag match