Skip to content

Instantly share code, notes, and snippets.

@randallreedjr
Last active March 22, 2016 16:59
Show Gist options
  • Save randallreedjr/27ba392b92082f5dca24 to your computer and use it in GitHub Desktop.
Save randallreedjr/27ba392b92082f5dca24 to your computer and use it in GitHub Desktop.
First code sample for post Ruby Abstraction in Loops
array = [1,2,3]
current_index = 0
squares = []
loop do
if current_index < array.size
squares << array[current_index] ** 2
current_index += 1
else
break
end
end
squares
# => [1,4,9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment