Created
July 14, 2010 05:17
-
-
Save ilyanep/475064 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Suppose I want to the user to enter names one at a time, until the user enters a blank line, | |
# then tell each name that they're awesome. In a typical programming language, my first instinct | |
# would be to do: | |
while (name = gets.chomp) != "" | |
puts name + ", you are so awesome" | |
# or perhaps alternatively, to get the names to print afterwards | |
names = Array.new | |
while (name = gets.chomp) != "" | |
names.push name | |
end | |
names.each do |nom| | |
puts "#{nom}, you are so awesome" | |
end | |
# But this is a very C way of doing things, and Ruby is supposed to be more elegant. How would you | |
# do this? Seems like there has to be a way of avoiding using a while loop, and it's probably actually | |
# really easy, but I'm just being dumb slash don't know Ruby that well. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment