On 10/01/2010 01:29 PM, Mica Koizumi wrote:
> Rick Denatale wrote:
>> On Fri, Oct 1, 2010 at 2:05 PM, Mica Koizumi <monkeymica / yahoo.com> 
>> wrote:
>>> if year1.to_i % 4 == 0
>>> leapyear = year1.to_i + 4
>>> puts leapyear
>>> end
>>
>> This says 'paraphrasing"
>>
>> if year1 is a leapyear then print year1 + 4
>>
>> 1988 is the only leap year between 1987 and 1990.
>>
>> 1988 + 4 is 1992
>>
> Thanks Rick -
>
> But the part that confuses me is:
>
> while (year1.to_i <= year2.to_i)
>
> Shouldn't that prevent 1992 from being printed?

That while condition is only evaluated at the beginning of each pass
through the loop.  The first pass (where 1987 <= 1900) adds 1 to year1
making it 1988.  The second pass (where 1988 <= 1990) sets *leapyear* to
year1 + 4 (1988 + 4 = 1992) and then prints *leapyear* which is now
1992; however, it does not modify the value of year1.  From hear on, the
loop continues printing 1992 infinitely because year1 is never updated
again and will always be 1988 which is less than 1990.

-Jeremy