Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!