PEP 315: Enhanced While Loop

D

Daniel Cotton

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>:
<code>

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>:
<code>

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.

--Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top