Last active
March 22, 2016 16:59
-
-
Save randallreedjr/27ba392b92082f5dca24 to your computer and use it in GitHub Desktop.
First code sample for post Ruby Abstraction in Loops
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
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