Since both your arrays have exactly the same indices (0, 1, 2, and 3), you can use ${!array[@]} to iterate over the indices (AKA keys) of one of the arrays and use that iterator to access the values in both arrays.
This works with both "indexed arrays" (i.e. with integer indices) and "associative arrays" (string indices).
e.g.
LABELS=(label1 label2 label3 labe4 )
VALUES=(91 18 7 4)
for i in "${!LABELS[@]}"; do
echo "${LABELS[i]}" "${VALUES[i]}"
done
Output:
label1 91
label2 18
label3 7
labe4 4
BTW, you can also use a loop like this to populate an associative array, which can be useful in situations where you can't just read the key and the value at the same time, as with your two manually defined arrays:
LABELS=(label1 label2 label3 labe4)
VALUES=(91 18 7 4)
declare -A LV # declare LV to be an associative array
for i in "${!LABELS[@]}"; do
LV["${LABELS[$i]}"]="${VALUES[$i]}";
done
declare -p LV
Output:
declare -A LV=([labe4]="4" [label3]="7" [label2]="18" [label1]="91" )
From now on, your script can use associative array $LV to directly access the value from the key, e.g.
$ echo "${LV[label1]}"
91
You can also use a C-style for loop as in @terdon's and @NickMatteo's answers (looping from 0 to the array's length), but that only works if the array indices are numeric and consecutive with no gaps (undefined indices) in the array.
In many/most cases, this is fine because arrays often are defined with consecutive index numbers, but in other cases it won't work as expected - e.g. if $array has defined indices for 1, 3, 5, 7, 11, 13, 17 then ${#array[@]} will return 7 and such a loop will iterate from 0..6 (or 0..7 if you use <= rather than < as the test condition) rather than over the list of actual indices in the array.
For example:
$ for i in 1 3 5 7 11 13 17 ; do let array[$i]=$i*$i ; done
$ declare -p array
declare -a array=([1]="1" [3]="9" [5]="25" [7]="49" [11]="121" [13]="169" [17]="289")
$ echo "${#array[@]}"
7
$ for ((i=0; i<"${#array[@]}"; i++)); do echo $i: "${array[$i]}" ; done
0:
1: 1
2:
3: 9
4:
5: 25
6:
$ echo "${!array[@]}"
1 3 5 7 11 13 17
$ for i in "${!array[@]}"; do echo $i: "${array[$i]}"; done
1: 1
3: 9
5: 25
7: 49
11: 121
13: 169
17: 289