PEP 315: Enhanced While Loop

Discussion in 'Python' started by Daniel Cotton, Jun 4, 2009.

  1. 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.
    Daniel Cotton, Jun 4, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wayne Folta

    PEP-315 ("do" loop)

    Wayne Folta, Feb 17, 2004, in forum: Python
    Replies:
    14
    Views:
    625
    Josiah Carlson
    Feb 19, 2004
  2. Wayne Folta

    Re: PEP-315 ("do" loop)

    Wayne Folta, Feb 17, 2004, in forum: Python
    Replies:
    2
    Views:
    284
    Wayne Folta
    Feb 18, 2004
  3. Wayne Folta

    Re: PEP-315 ("do" loop)

    Wayne Folta, Feb 17, 2004, in forum: Python
    Replies:
    1
    Views:
    294
  4. Andrew Koenig
    Replies:
    46
    Views:
    996
    Peter Maas
    Feb 24, 2004
  5. Isaac Won
    Replies:
    9
    Views:
    372
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page