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 trialUnsubscribed User
1,266 Pointsdoes 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
KRIS NIKOLAISEN
54,971 Pointsitem
takes the value at the time it is assigned. Without putting the assignment in the loop item
will always be arr[0]
.