From: Morton Goldberg Date: 2006-07-26T14:31:14+09:00 Subject: Re: Learn to program (Chris Pine) array.sort You're very close to what is needed. The following variation on your code will do the job. Regards, Morton #! /usr/bin/ruby -w array_input = [] loop do input = gets.chomp break if input.empty? array_input << input end puts puts array_input.sort On Jul 26, 2006, at 12:55 AM, Geoff wrote: > "Write the program we talked about at the very beginning of this > chapter. > Hint: There's a lovely array method which will give you a sorted > version of an array: sort. Use it!" > >> From the beginning of the chapter: > > "Let's write a program which asks us to type in as many words as we > want (one word per line, continuing until we just press Enter on an > empty line), and which then repeats the words back to us in > alphabetical order." > > Here is what I have that works, but I had to change it in order to get > the program to exit. You see I can't seem to get the program to exit > on just entering a blank line at the prompt, so I wrote some code so > that it would quit with when I entered the word "bye." > > array_input = [] > input = '' > while input != "bye" > input = gets.chomp > array_input << input > end > puts > array_input.delete_if { |x| x == 'bye' } > puts array_input.sort > > Problem is I would actually like to know how to solve the problem as > written! So when I use "while input != "something goes here and I'm > not sure what to use to designate a blank line." Then I can eliminate > the second to the last line.