From: tamouse mailing lists Date: 2013-02-10T07:34:44+09:00 Subject: Re: Deaf Grandma On Fri, Feb 8, 2013 at 12:25 PM, Anna Fedorova wrote: > For the full iteration of the problem (upcase, random years & triple BYE > in a row requests), I've got a slightly simpler structure, the code > makes sense to me structurally & intuitively: > > puts 'Hello there, Sonny. It\'s your grandma!' > reply = gets.chomp > > while reply != 'BYE' > if reply == reply.upcase > puts 'NO, NOT SINCE ' +(rand(21)+1930).to_s+ '!' > reply = gets.chomp > else > puts 'HUH?! SPEAK UP, SONNY!' > reply = gets.chomp > end > if reply == 'BYE' > puts 'CAN\'T HEAR YOU, DEAR!' > reply = gets.chomp > if reply == 'BYE' > puts 'STILL CAN\'T HEAR YOU, DEAR!' > reply = gets.chomp > if reply == 'BYE' > end > end > end > > -- > Posted via http://www.ruby-forum.com/. > Still LOTS of repetition here. DRY: Don't Repeat Yourself, not only saves typing, and time, but might also lead to better understanding of algorithms. See if you can write it with only one gets per loop.