From: Jason Mayer Date: 2006-12-02T01:02:49+09:00 Subject: Re: loops and branching ------=_Part_3645_27706042.1164988965126 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/30/06, ishamid wrote: > > Thank you, but the following does not work properly: > > ================ > puts 'Type initial year:' > leapi = gets.chomp.to_i > puts 'Type final year:' > leapf = gets.chomp.to_i > > puts '' > > while (leapi + (4 - leapi%4)) <= leapf > leapi = (leapi + (4 - leapi%4)) > (leapi..leapf).select do |x| > (x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0) > puts leapi > end > end > ================ > > Please advise ;-) > > Best and Thnx > Idris > > On Nov 30, 3:11 pm, "Christoffer Sawicki" > wrote: > > > if leapi%4 == 0 && (leapi%400 == 0 || leapi%100 != 0) > > > puts leapi > > > else > > > end > > > > > while (leapi + (4 - leapi%4)) <= leapf > > > leapi = (leapi + (4 - leapi%4)) > > > if leapi%4 == 0 && (leapi%400 == 0 || leapi%100 != 0) > > > puts leapi > > > else > > > end > > > end(leapi..leapf).select do |x| > > (x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0) > > end > > > > -- > > Christoffer Sawickihttp://vemod.net/ > > > puts 'Enter a starting year' num1 = gets.chomp.to_i puts 'Enter an ending year' num2 = gets.chomp.to_i puts 'The leap years between ' + num1.to_s + ' and ' + num2.to_s + ' are: ' (num1..num2).select do |x| if (x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0) puts x end end ------=_Part_3645_27706042.1164988965126--