Skip to content

Instantly share code, notes, and snippets.

@tight
Created February 7, 2012 10:07
Show Gist options
  • Save tight/1758913 to your computer and use it in GitHub Desktop.
Save tight/1758913 to your computer and use it in GitHub Desktop.
for vs each
i = "foo"
for i in 1..5 do
puts i
j = "bar"
end
i # => 5
j # => "bar"
i = "foo"
(1..5).each do |i|
puts i
k = "bar"
end
i # => "foo"
k # => NameError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment