From f3a113f370abe3d94617a80114fc9ede5baa0b96 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 15 Jun 2018 16:43:03 +1000 Subject: [PATCH] Added loops --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) 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.