Created
October 11, 2011 11:32
-
-
Save evansagge/1277867 to your computer and use it in GitHub Desktop.
Ruby question: for loop vs. iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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