From: sto.mar@... Date: 2013-01-25T05:03:43+09:00 Subject: Re: Leap year programing Am 24.01.2013 02:01, schrieb Kristine Lai: > Thanks for the pointers Eduardo! > > The new code here works. > --------------------------------------- > > puts "Enter starting year:" > starting_year = gets.chomp.to_i > puts "Enter ending year:" > ending_year = gets.chomp.to_i > year = starting_year > while true > if year%4==0 > if year%100!=0 || year%400 ==0 > puts year.to_s + ' is a Leap Year' > end > end > year = year +1 > break if year >= ending_year > end Usually you would not use a while loop for tasks like this, try for example: print "Enter starting year: " starting_year = gets.chomp.to_i print "Enter ending year: " ending_year = gets.chomp.to_i starting_year.upto(ending_year) do |year| if year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) puts "#{year} is a leap year" end end which saves 3 lines of code and some possibilities for typos/bugs. BTW, for an infinite loop there exists `loop do ... end'. --