HB wrote: > Hi, All, > > I am a beginner on programming now reading books by Chris Pine: Learn > to Program. > > ... > > while ( (s.to_i % 4 == 0 and s.to_i % 100 != 0) or (s.to_i % 100 == > 0 and s.to_i % 400 == 0 )) > > The key point of all the methods proposed in this thread is: deal > with the years divisible by 400 first, the years divisible by 100 > second, and the years divisible by 4 last of all. > > Regards, Morton Your complex conditional can be expressed more clearly with a series of if statements: start = 2000 finish = 2200 year = start while year <= finish is_leap = if year % 400 == 0 true elsif year % 100 == 0 false else year % 4 == 0 end if is_leap: puts year end year += 1 end Or you can use each() on a Range for your loop, and a case statement inside the loop: start = 2000 finish = 2200 user_range = start..finish user_range.each do |year| is_leap = case when year % 400 == 0 true when year % 100 == 0 false else year % 4 == 0 end if is_leap: puts year end year += 1 end -- Posted via http://www.ruby-forum.com/.