Try It Out (5.5) Curly Brackets?


I'm having an issue with the "Try it Out" section under Loops & Iterations.

According to the instructions on the exercise, I should be able to use the curly brackets instead of "do." as in

odds.each { |x| ...... }

However, no matter how hard I tried, it returned a syntax error. The instant I changed to "do," it worked like a charm.

While I have successfully completed the exercise, I now feel like I understand less than when I started. Can somebody please clarify whether the curly brackets actually work? And if so, how to complete this exercise using them?

Looking at the hint does not help at all, as the hint makes no mention of the curly brackets, despite them being in the initial example in the instructions.


It's hard to say what is the problem without seeing your code or the error message.

You are completely right, you can use curly braces instead of do.

These two codes have exactly the same result:

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

odds.each do |x|
    print x *= 2

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

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