i=2; lst=[i**=2 while i<1000]

Steve Holden steve at holdenweb.com
Tue Dec 6 11:47:13 EST 2005


Carsten Haese wrote:
> On Tue, 2005-12-06 at 10:44, Steve Holden wrote:
> 
>>Daniel Schüle wrote:
>>
>>>>>i=2
>>>>>lst=[]
>>>>>while i<1000:
>>>>>   i**=2
>>>>>   lst.append(i)
>>>>>
>>>>
>>>unless I am missing something obvious, I can not see why the loop should 
>>>not terminate
>>
>>In that case, kindly explain how the condition i<1000 can become false 
>>when it starts at 2 and never changes! [In other words: you *are* 
>>missing something obvious].
>>
>>Don't you have an interpreter you could run the code in to verify that 
>>it does indeed loop interminably? You seem to be assuming that the 
>>expression i**2 changes the value of i. It doesn't.
> 
> 
> Note that the OP wrote i**=2, not i**2.
> 
Oops. Thanks :-)

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list