Bash Control Structures Looping over an array

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

for loop:

arr=(a b c d e f)
for i in "${arr[@]}";do
    echo "$i"
done

Or

for ((i=0;i<${#arr[@]};i++));do
    echo "${arr[$i]}" 
done

while loop:

i=0
while [ $i -lt ${#arr[@]} ];do
    echo "${arr[$i]}"
    i=$(expr $i + 1)
done

Or

i=0
while (( $i < ${#arr[@]} ));do
    echo "${arr[$i]}"
    ((i++))
done


Got any Bash Question?