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

does ruby ignore updates to index because its not in the why condition? is index updated and not referenced?

def arr_writer(arr)
  i = 0
  item = arr[i]
  while i < arr.length
    puts "The current item is #{item} for index #{i}"
    i+=1
  end
end
```ruby 

a simple fix is to update the item variable inside the while loop but this seems wrong? 

```ruby 
def arr_writer(arr)
  i = 0
  item = arr[i]
  while i < arr.length
    puts "The current item is #{item} for index #{i}"
    i+=1
    item =arr[i]
  end
end
```ruby

1 Answer

item takes the value at the time it is assigned. Without putting the assignment in the loop item will always be arr[0].