Monday, October 16, 2006


do-while loops in Python

It just occurred to me today that apparently Python does not have a "do-while" type of loop, or any equivalent. The most obvious usage for this would be :
f = open ( filename )
   buf =
while buf

suggestions on how to handle situation like this in Python vary, from using "break" in traditional "while" loop to avoiding (any form of) while altogether, using Python-style "for" instead.

Apparently, there is PEP (Python Enhancement Proposal) 315 pending since 2003 that would request just that, a "do-while" loop implementation. This was considered at some point as a possible candidate for Python 2.5, but was rejected as not that important, and this comment and recent discussion at python-dev mailing list revealed lack of consensus on simple, implementable, Python-style syntax for "do-while" loops.

It seems like therefore this will have to wait (at best) till "Python 3000" version of Python (a.k.a. "Py3k" or sometimes even "p3yk"), which is kind of sad.

BTW, this presentation has a nice overview of Py3k plans and ideas.


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?