Hi Nick,

Yep, PEP 315. Sorry about that.

Now, about your suggestion 
     do:
         <setup code>
         while <condition>
         <loop body>
     else:
         <loop completion code>

This is pythonic, but not logical. The 'do' will execute at least once, so
the else clause is not needed, nor is the <loop completion code>.  The <loop
body> should go before the while terminator.

I'm bound to reiterate my proposal:

        <before loop code>
        do:
                <loop body>
                <setup code>
                while <condition>
        <after loop code>

Example (if you know there will be at least one val).
        source.open()
        do:
                val = source.read(1)
                process(val)
                while val != lastitem
        source.close()

The c syntax is:
do
{
     block of code
} while (condition is satisfied);

The VB syntax is:
do
        block
loop while <cond>

Cheers & thanks for your reply,
Hans Polak.

-----Original Message-----
From: Nick Coghlan [mailto:[EMAIL PROTECTED] 
Sent: domingo, 01 de octubre de 2006 6:18
To: Hans Polak
Cc: python-dev@python.org
Subject: Re: [Python-Dev] PEP 351 - do while

Hans Polak wrote:
> Hi,
> 
>  
> 
> Just an opinion, but many uses of the 'while true loop' are instances of 
> a 'do loop'. I appreciate the language layout question, so I'll give you 
> an alternative:
> 
>  
> 
> do:
> 
>             <body>
> 
>             <setup code>
> 
>             while <condition>
> 

I believe you meant to write PEP 315 in the subject line :)

To fully account for loop else clauses, this suggestion would probably need
to 
be modified to look something like this:

Basic while loop:

     <setup code>
     while <condition>:
         <loop body>
         <setup code>
     else:
         <loop completion code>


Using break to avoid code duplication:

     while True:
         <setup code>
         if not <condition>:
             <loop completion code>
             break
         <loop body>

Current version of PEP 315:

     do:
         <setup code>
     while <condition>:
         <loop body>
     else:
         <loop completion code>

This suggestion:

     do:
         <setup code>
         while <condition>
         <loop body>
     else:
         <loop completion code>

I personally like that style, and if the compiler can dig through a function

looking for yield statements to identify generators, it should be able to
dig 
through a do-loop looking for the termination condition.

As I recall, the main objection to this style was that it could hide the
loop 
termination condition, but that isn't actually mentioned in the PEP (and in 
the typical do-while case, the loop condition will still be clearly visible
at 
the end of the loop body).

Regards,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient,  you are not authorized 
to read, print, retain, copy, disseminate,  distribute, or use this message or 
any part thereof. If you receive this  message in error, please notify the 
sender immediately and delete all  copies of this message.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to