From: Adriano Ferreira Date: 2010-10-02T09:53:35+09:00 Subject: Re: New to Ruby, Looking for Help With Basic Program --0-40649529-1285980811=:55190 Content-Type: text/plain; charset=us-ascii Hi Mica, Now it does, with some refactoring: year1 = 1987 year2 = 1990 puts (year1 % 4 == 0 ? year1 + 4 : year1 + 1) while year1 <= year2 # => 1988 ... Hope it helped. Adriano ________________________________ From: Mica Koizumi To: ruby-talk ML Sent: Fri, October 1, 2010 3:05:20 PM Subject: New to Ruby, Looking for Help With Basic Program I am teaching myself Ruby and am trying to figure out why this program is doing what it is doing: puts 'Year 1?' year1 = gets.chomp puts 'Year 2?' year2 = gets.chomp while (year1.to_i <= year2.to_i) if year1.to_i % 4 == 0 leapyear = year1.to_i + 4 puts leapyear end if year1.to_i % 4 != 0 year1 = year1.to_i + 1 puts year1 end end When year1 = 1987 and year2 = 1990, why is it printing out 1992? I am expecting 1988. Thanks in advance... -- Posted via http://www.ruby-forum.com/. --0-40649529-1285980811=:55190--