From: Rick DeNatale Date: 2009-07-19T05:17:50+09:00 Subject: Re: Ordering Steps in a Program On Sat, Jul 18, 2009 at 3:23 PM, Max Norman wrote: > Here is a simple program that stores entered words in an array, then, > once a blank line is entered, displays them sorted alphabetically > (another example from Pine's book.) Here are two ways of accomplishing > this. > > #1: > puts 'Enter words to sort them alphabetically. When you are finished, >      press "return" on an empty line' > > words = [] > > while true >  word = gets.chomp >  if word == '' >    break >  end >  words.push word > end > > puts 'Here they are:' > puts words.sort > > -- > > #2: > puts 'Use this application to sort any number of words. Enter them > below:' > > words = [] > > while true >  word = gets.chomp >  words.push word >  if word =='' >    break >  end > end > > puts 'Here are the words you entered, sorted:' > puts words.sort > > -- > > Which one is more correct? The former was presented by Pine as a > possible solution, and the latter is what I came up with after > consulting this suggestion. The difference is that yours will include the empty string in the array to be sorted. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale