From: Eduardo Bautista Date: 2013-01-23T13:45:01+09:00 Subject: Re: Leap year programing --_47b23bec-444f-4d11-a900-74eed2b70f64_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable You are resetting year to starting_year every time the loop runs. Set that= variable outside of the loop. Also=2C every 400 years=2C there is a leap = year. > Date: Wed=2C 23 Jan 2013 13:32:20 +0900 > From: lists@ruby-forum.com > Subject: Re: Leap year programing > To: ruby-talk@ruby-lang.org >=20 > Hi=2C 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! >=20 > puts "Enter starting year:" > starting_year =3D gets.chomp.to_i > puts "Enter ending year:" > ending_year =3D gets.chomp.to_i > while true > year =3D starting_year > if (year%4=3D=3D0)&& (year%100!=3D0) > puts year.to_s + ' is a Leap Year' > end > year =3D year +1 > break if year >=3D ending_year > end >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 = --_47b23bec-444f-4d11-a900-74eed2b70f64_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
You are resetting year to s= tarting_year every time the loop runs.  =3BSet that variable outside of= the loop.  =3BAlso=2C every 400 years=2C there is a leap year.

=
>=3B Date: Wed=2C 23 Jan 2013 = 13:32:20 +0900
>=3B From: lists@ruby-forum.com
>=3B Subject: Re: = Leap year programing
>=3B To: ruby-talk@ruby-lang.org
>=3B
&g= t=3B Hi=2C I'm also a newbie trying the Leap Year problem using while loops= ..
>=3B Can anyone advice why the following code doesn't work? Much t= hanks!
>=3B
>=3B puts "Enter starting year:"
>=3B sta= rting_year =3D gets.chomp.to_i
>=3B puts "Enter ending year:"
>= =3B ending_year =3D gets.chomp.to_i
>=3B while true
>=3B = year =3D starting_year
>=3B if (year%4=3D=3D0)&=3B&=3B= (year%100!=3D0)
>=3B puts year.to_s + ' is a Leap Year'
= >=3B end
>=3B year =3D year +1
>=3B break if ye= ar >=3B=3D ending_year
>=3B end
>=3B
>=3B --
>=3B P= osted via http://www.ruby-forum.com/.
>=3B
=
= --_47b23bec-444f-4d11-a900-74eed2b70f64_--