2つのインデックスを持つrubyforループを作成できますか?すなわち:
for i,j in 0..100
do something
end
グーグルで何も見つかりません
編集:詳細を追加
私はそのような2つの異なる配列を比較する必要があります
Index: Array1: Array2:
0 a a
1 a b
2 a b
3 a b
4 b b
5 c b
6 d b
7 d b
8 e c
9 e d
10 e d
11 e
12 e
しかし、両方が同じアイテムを持っていることを知っている(abcde)これは疑似の私の論理です、このすべてがループの中にあると仮定しましょう
#tese two if states are for handling end-of-array cases
If Array1[index_a1] == nil
Errors += Array1[index_a1-1]
break
If Array2[index_a1] == nil
Errors += Array2[index_a2-1]
break
#this is for handling mismach
If Array1[index_a1] != Array2[index_a2]
Errors += Array1[index_a1-1] #of course, first entry of array will always be same
if Array1[index_a1] != Array1[index_a1 - 1]
index_a2++ until Array1[index_a1] == Array2[index_a2]
index_a2 -=1 (these two lines are for the loop's sake in next iteration)
index_a1 -=1
if Array2[index_a2] != Array2[index_a2 - 1]
index_a1++ until Array1[index_a1] == Array2[index_a2]
index_a2 -=1 (these two lines are for the loop's sake in next iteration)
index_a1 -=1
一言で言えば、上記の例では、
Errors looks like this
a,b,e
cとdが良いので。