[Python-ideas] Immemorial desire for "do-while"-like construction

Chris Rebert pyideas at rebertia.com
Thu Jul 16 00:54:07 CEST 2009


On Wed, Jul 15, 2009 at 3:50 PM, Jan Kaliszewski<zuo at chopin.edu.pl> wrote:
> Hello,
>
> The issue has been coming back repeatedly:
>
> How we could elegantly and pythonic'ly avoid repeating ourselves if
> we need the control flow structure that e.g. in PASCAL has the form:
>
> repeat
> ...
> until CONDITION
>
> In Python we must use while-loop in not very DRY (Don't Repeat
> Yourself) manner:
>
> SOME
> ACTIONS
> HERE
> ...
> while CONDITION:
>      THE SAME
>      ACTIONS
>      AGAIN
>      ...

You can fix that by just writing it as:

while True:
    SOME
    ACTIONS
    HERE
    if not CONDITION: break

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-ideas mailing list