Skip to content

Instantly share code, notes, and snippets.

@evansagge
Created October 11, 2011 11:32
Show Gist options
  • Save evansagge/1277867 to your computer and use it in GitHub Desktop.
Save evansagge/1277867 to your computer and use it in GitHub Desktop.
Ruby question: for loop vs. iterator
# example 1:
values = [1, 2, 3, 4, 5]
current_value = 0
for value in values do
current_value = value
end
puts current_value
# example 2:
values = [1, 2, 3, 4, 5]
current_value = 0
values.each do |value|
current_value = value
end
puts current_value
# Specify the output for each example, and explain why they're similar and/or different.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment