Newbie question: Explain this behavior - a followup

David Smith ac063 at lafn.org
Wed Jul 20 11:33:39 EDT 2005


max wrote:
> David Smith <ac063 at lafn.org> wrote in
> news:db99ec$2epm$1 at zook.lafn.org: 
> 
> 
>>range statements, the example doesn't work.
>>
>>Given that the beginning and ending values for the inner range
>>statement are the same, the inner range statement will never be
> 
> 
> Is your question about the semantics of for else blocks or about the 
> suitability of the algorithm given in the example? The for else block 
> is behaving exactly as expected...
> 
> 

Good question.  The question was directed at the latter, the suitability 
of algorithm for determining prime numbers.

>>>>range(1,1)
> 
> []
> 
>>>>range(500,500)
> 
> []
> 
> 
> see 
> http://groups-
> beta.google.com/group/comp.lang.python/browse_frm/thread/d6c084e791a00
> 2f4?q=for+else&hl=en&
> 
> for a good explanation of when the else part of the loop is executed. 
> Basically, whenever the loop is exited normally, which is what happens 
> when you iterate over an empty list like the one returned by 
> range(1,1)
> 
> 
> max
> 
> 



More information about the Python-list mailing list