From: Pete Yandell Date: 2006-12-03T08:48:51+09:00 Subject: Re: loops and branching On 02/12/2006, at 3:02 AM, Jason Mayer wrote: > 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 Errr...that's not really a good use of select. You probably meant: (num1..num2).each do |x| if (x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0) puts x end end Although I prefer separating the calculation and the output: leap_years = (num1..num2).select {|x| (x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0) } leay_years.each do {|x| puts x } Pete Yandell