On Oct 1, 1:05=A0pm, Mica Koizumi <monkeym... / yahoo.com> wrote:
> I am teaching myself Ruby and am trying to figure out why this program
> is doing what it is doing:
>
> puts 'Year 1?'
> year1 =3D gets.chomp
> puts 'Year 2?'
> year2 =3D gets.chomp
>
> while (year1.to_i <=3D year2.to_i)
> if year1.to_i % 4 =3D=3D 0
> =A0 leapyear =3D year1.to_i + 4
> =A0 puts leapyear
> end
> if year1.to_i % 4 !=3D 0
> =A0 year1 =3D year1.to_i + 1
> =A0 puts year1
> end
> end
>
> When year1 =3D 1987 and year2 =3D 1990, why is it printing out 1992? I am
> expecting 1988.
>
> Thanks in advance...
> --
> Posted viahttp://www.ruby-forum.com/.

puts (1987..1999).select{|n| 0 =3D=3D n%4 }
1988
1992
1996