I tried to execute this code in Ruby:
array=[1,2,3,4,5]
array.each do |x|
puts array.length
puts "Downloading #{array.length} files"
array.pop
end
I got:
5
Downloading 5 files
4
Downloading 4 files
3
Downloading 3 files
I don't understand why I'm getting only three iterations. What am I doing wrong (apart from not using a while
loop)?