From: "Eduardo B." Date: 2013-01-23T13:45:11+09:00 Subject: Re: Leap year programing Kristine Lai wrote in post #1093222: > Hi, I'm also a newbie trying the Leap Year problem using while loops.. > Can anyone advice why the following code doesn't work? Much thanks! > > puts "Enter starting year:" > starting_year = gets.chomp.to_i > puts "Enter ending year:" > ending_year = gets.chomp.to_i > while true > year = starting_year > if (year%4==0)&& (year%100!=0) > puts year.to_s + ' is a Leap Year' > end > year = year +1 > break if year >= ending_year > end You are resetting the variable "year" to "starting_year" every time to loop runs. Set the variable "year" outside of the while loop. Also, there is a leap year every 400 years. -- Posted via http://www.ruby-forum.com/.