diff --git a/README.md b/README.md index d1bcf1c..acf1af8 100644 --- a/README.md +++ b/README.md @@ -596,10 +596,17 @@ done ## Loop over an array with an index. ```shell +arr=(apples oranges tomatoes) + # Elements and index. for i in "${!arr[@]}"; do printf '%s\n' "${arr[$i]}" done + +# Alternative method. +for ((i=0;i<${#arr[@]};i++)); do + printf '%s\n' "${arr[$i]}" +done ``` ## Loop over the contents of a file.