Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Loops Ruby Iteration Iteration With Each

Thomas Minnick
Thomas Minnick
2,539 Points

whats the difference between what Jason has in the video and this code?

1 In the video he has the code 2 array = [0, 1, 2, 3, 4, 5] 3 array.each do |item| 4 item = item + 2 5 puts "The current item + 2 is #{item}." 6 end

But on like 4 he has item = item + 2

would it be doing the same thing if I were to put it as

item += 2

or would this have a different meaning entirely?

1 Answer

Yes, it is the same. When you come up with this kind of questions, the best thing is actually to try it and see what happens, being curious and trying things is a great way to learn the little details. Cheers.

Thomas Minnick
Thomas Minnick
2,539 Points

I did try it, but I feared maybe it was similar to puts and print where they are completely different but for what I was using them for they showed up the same. Thanks for the answer!