From: Brian Candler Date: 2010-12-13T18:59:30+09:00 Subject: Re: Deaf Grandma danielj wrote in post #719787: > Is there an easier way? Remember to set your bye counter to zero in every case except where 'BYE' is typed, to ensure three BYE's in a row are required. You can use 'next' to skip straight to the top of the next iteration, which means you can put a single bye=0 at the end of the loop. Also, I think there is some ambiguity in the original problem description: what should happen if what you type contains neither upper nor lower case letters? (e.g. empty text or only punctuation characters?). In the code below I've let grandma have a snooze. I also use the 'case' statement to match the response against a series of values and regexp patterns. puts "Hey Sonny, it's your Grandma! How are you?" bye = 0 loop do case gets.chomp when "BYE" bye += 1 break if bye >= 3 next when /[a-z]/ puts "HUH?! SPEAK UP, SONNY!" when /[A-Z]/ puts "NO, NOT SINCE #{rand(21)+1930}!" else puts "ZZZ" end bye = 0 end But to be honest, I'd say that if...elsif...elsif...end is equally good. -- Posted via http://www.ruby-forum.com/.