Loops and iterator--do


#1

In the excercise where I am asked to print out double the value of each item of the array, the way to use "do " to loop worked, syntax like below:
odds=[1,3,5,7,9]
odds.each {|x| print x*2}

HOWEVER, the attempt to loop using the brackets failed:
odds=[1,3,5,7,9]
array.each do |x|
x=x*2
print "#{x}"
end

What is wrong with the code above?
Also, to make the placeholder mutiplied by 2, can I use x*=2? How to use the opertor *= in general?

Thank you.


Replace this line with your code.


#2

Your code
odds=[1,3,5,7,9]
array.each do |x|
x=x*2
print "#{x}"
end

odds = [1,3,5,7,9]
odds.each do |x|
print x * 2
end

OR

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

odds.each { |x| print x * 2}