I am trying that when the for
exterior% completes an iteration, the variable i
is updated, in the way that is indicated in the if
after the for
internal ( if i+self.nGroups > n
)
for i in 0..n
for j in 0..self.nGroups-1
if i+j <= n
puts "i=#{i} , j=#{j}"
@competition_users[i+j].group = j+1
puts @competition_users[i+j].group
@competition_users[i+j].save
end
end
if i+self.nGroups > n
i += 1
else
i += self.nGroups
end
end
For the values n=4
, nGroups=2
, unfortunately the output of the puts
is the following:
i=0 , j=0
1
i=0 , j=1
2
i=1 , j=0
1
i=1 , j=1
2
i=2 , j=0
1
i=2 , j=1
2
i=3 , j=0
1
i=3 , j=1
2
i=4 , j=0
1
When what I expect is:
i=0 , j=0
1
i=0 , j=1
2
i=2 , j=0
1
i=2 , j=1
2
i=4 , j=0
1
Basically, the i
index does not change when I perform i += self.nGroups
Let's see if anyone can explain why it is, or if they can advise me to do it in another way. Thanks