Problem with nested while do

Hallo,
I am new to Ruby and I can’t solve this Problen.

I’ve got an Array w with 100 Elements called “w”.
I want to divide the array with 1…100 divisors.

i = 0
j = 1.0

w.each do |i|

while j <= 100.0 do

   print i/j,  ", "


   j +=1.0

end

end

but it’s not working.
Only the first Element of the Array is divided with
the hundred divisors.

I’d be very grateful for help.
Martin

you need to declare “j” inside the “each” loop. By declaring it at the
top, you’re reaching j == 100, but you never set it back to 1.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs