PEP 315: Enhanced While Loop

Daniel Cotton daniel.cotton at
Thu Jun 4 11:41:18 EDT 2009

During some random surfing I became interested in the below piece of code:

> while <condition1>:
>             <code1>
>         and while <condition2>:
>             <code2>
>         and while <condition3>:
>             <code3>
> else: <other code>

It strikes me that the 'and while' syntax has some power that you may
not have considered. Consider that if an 'and while' were to be
executed under some condition:

             if <conditionX>:
         and while <conditionY>:

you would then have a live loop condition that applied to subsequent
iterations only if conditionX was met. Under this circumstance I
wondered if you might also want a method of cancelling while
conditions? For example:

          cancel while <conditionY>:

where the 'cancel while' command removes conditionY from the list of
conditions that the loop will terminate on. You could then also use
this syntax to cancel the initial while condition.

I also wondered if 'or while' might be better, so that you could add
different types of prefix to a while condition, i.e. 'and while'.

I'm a python novice so this could well be something you want to ignore
but I wasn't doing anything anyway. Let me know what you think.


More information about the Python-list mailing list