Loop .each


#1

odds = [1,3,5,7,9]

odds.each do |x|
x*2
print "#{x}"
end

Hi,

I am trying to double the value of each array but I am struck. Someone can help ?
Thx

Abel


#2

Hi try to put it like that

x = x * 2

#3

thx a lot. I tried *= and it worked. I don't know why we need the = for the multiplication. do you have any idea ?


#4

the = it's for asegning something to a variable and the *= works like that

x *= 2
same as..
x = x * 2

#5

a big thank you wizmarco for your help !