each vs for Ruby
Using each
keeps your iterator variable within scope:
ruby
["apple", "banana", "pomegranate"].each { |fruit| }
fruit # => NameError! undefined variable
Whereas for
leaves a dangling iterator variable:
ruby
for fruit in ["apple", "banana", "pomegranate"] do
fruit
end
fruit # => "pomegranate"