Problem Statement
Which is the correct syntax for a for loop in bash?
Explanation
For loop syntax: for VAR in list; do commands; done. Alternative format:
```bash
for VAR in list
do
commands
done
```
VAR takes each value from list sequentially. List can be explicit: for i in 1 2 3; do echo $i; done, or generated from commands: for file in *.txt; do echo $file; done.
Common patterns: loop through files for file in /path/*; do echo "$file"; done, loop through array for item in "${ARRAY[@]}"; do echo "$item"; done, loop through command output for user in $(cat users.txt); do echo $user; done. Use "$@" for script arguments: for arg in "$@"; do echo "$arg"; done.
C-style for loop (bash-specific): for ((i=0; i<10; i++)); do echo $i; done. Useful for numeric ranges with counter control. Ranges with brace expansion: for i in {1..10}; do echo $i; done generates 1 through 10. Step with {start..end..step}: for i in {0..100..10}; do echo $i; done counts by tens.
Break exits loop early, continue skips to next iteration. Understanding for loops enables iteration over files, arrays, ranges, and command output in scripts.
