Skip to content

Instantly share code, notes, and snippets.

@claytonflesher
Created May 16, 2015 16:44
Show Gist options
  • Save claytonflesher/396fbfa31acea06b8596 to your computer and use it in GitHub Desktop.
Save claytonflesher/396fbfa31acea06b8596 to your computer and use it in GitHub Desktop.
def while_loop(numbers)
i = 0
answer = 0
while i < (numbers.length)
answer += numbers[i]
i += 1
end
return answer
end
def each_method(numbers)
answer = 0
numbers.each { |number| answer += number }
return answer
end
numbers = [1, 2, 3, 4, 5]
puts while_loop(numbers)
puts each_method(numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment