goto

Mike Meyer mwm at mired.org
Thu Jul 21 19:32:06 EDT 2005


Rocco Moretti <roccomoretti at hotpop.com> writes:

>> My "favorite" infinte loop with while is:
>>    i = 0
>>    while i < 20:
>>          do_process(i)
>> Note the prominent *lack* of any change to i here?
>> Oh, for:
>>     from i = 0
>>     invariant 0 <= i <= 20
>>     variant 21 - i
>>     until i > 19
>>     loop
>>         do_process(i)
>> which throws an exception at the beginning of the second loop.
>
> What language is that from?

Eiffel.

> I take it the exception is from the "21-i" not changing as it goes
> around the loop, right? (But why can't "variant i" work just as well?)

Because that's the way variant is defined. You actually want the
variant to move in a specific direction, so that you don't wind up
incrementing it when you should be decrementing it. Eiffel chose down,
so you you need -i at the very least. It also insists that the
invariant be positive. I'm not sure why; it makes the variant more
complicated, resulting in exceptions from bugs in the variant as well
as bugs in the loop.

          <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list