On Jun 26, 2006, at 20:24, Dark Ambient wrote: > Sorry, meant to put this in the last reply. One thing I noticed is > that by removing the method definition I can get the loop to work. I > did change some of the verbage around though. > I commentd out the def method , and changed the end condition to > !='stop' but when I contain it in the method it no longer works. > Makes me wonder about methods. Are you calling the method? Or just defining it? This defines a method: def sortwords u_words = [] word = '' while word != 'stop' puts "enter a word" word = gets.chomp.downcase u_word.push[word] end u_words.sort end This actually calls/executes it: sortwords # (input 'foo', 'bar', 'baz', 'stop') => ["bar", "baz", "foo", "stop"] You'll notice that you get the 'stop' on the end of the array, which probably isn't what you want. > If I left sort alone in the > first 2 lines above, but then assigned another variable = > gets.....,then I won't know the user wants to quit. Unless... you check THAT variable. Maybe like this: def sortwords words = [] continue = false while continue word = gets.chomp.downcase if word == 'stop' continue = false elsif word == 'hello' # or some other special case. puts "hello yourself" else # default behaviour words.push(word) end end return words.sort end sortwords # (input 'foo', 'bar', 'baz', 'stop') => ["bar", "baz", "foo"] matthew smillie.