<div dir="ltr">and "while not except"  :-/   maybe we just stick with "while True' and put forward a documenting<div>PEP advising linter packages to look for ways of getting out of the loop. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 June 2017 at 08:08, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 6/26/2017 12:41 AM, Nick Coghlan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 26 June 2017 at 10:25, Rob Cliffe <<a href="mailto:rob.cliffe@btinternet.com" target="_blank">rob.cliffe@btinternet.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On 25/06/2017 12:58, Markus Meskanen wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I'm a huge fan of the do...while loop in other languages, and it would<br>
often be useful in Python too, when doing stuff like:<br>
<br>
while True:<br>
     password = input()<br>
     if password == ...:<br>
         break<br>
<br>
[...]I suggest [...]<br>
<br>
do:<br>
     password = input('Password: ')<br>
     until password == secret_password<br>
<br>
     # This line only gets printed if until failed<br>
     print('Invalid password, try again!')<br>
<br>
<br>
</blockquote>
I don't see any significant advantage in providing an extra Way To Do It.<br>
Granted, the "while True" idiom is an idiosyncrasy, but it is frequently<br>
used and IMHO intuitive and easy to get used to.  Your suggestion doesn't<br>
even save a line of code, given that you can write:<br>
<br>
     while True:<br>
         password = input('Password:')<br>
         if password == secret_password: break<br>
         print('Invalid password, try again!')<br>
</blockquote>
<br>
Right, this is the key challenge for do-while loops in Python: can you<br>
come up with something that's significantly clearer than the current<br>
"while True/if/break" pattern?<br>
<br>
The biggest weakness of that idiom is that it isn't really explicit in<br>
the header line - there's nothing about "while True:" that directly<br>
tells the reader "This loop is expected to exit via a break<br>
statement".<br>
<br>
If we wanted to allow that to be expressed literally, we could<br>
probably special case the "while not break" keyword sequence as a do<br>
loop:<br>
<br>
     while not break:<br>
         # Setup<br>
         if condition: break<br>
         # Loop continuation<br>
</blockquote>
<br></div></div>
We would then also need 'while not return:'<span class="im HOEnZb"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That more explicit declaration of intent ("The code in the loop body<br>
will conditionally break out of this loop") would allow a couple of<br>
things:<br>
<br>
- the compiler could warn that an else clause attached to such a loop<br>
will never execute (technically it could do that for any expression<br>
that resolves to `True` as a constant)<br>
- code linters could check the loop body for a break statement and<br>
complain if they didn't see one<br>
<br>
Logically, it's exactly the same as writing "while True:", but whereas<br>
that spelling suggests "infinite loop", the "while not break:"<br>
spelling would more directly suggest "terminated inside the loop body<br>
via a break statement"<br>
</blockquote>
<br>
<br>
<br>
<br></span><span class="HOEnZb"><font color="#888888">
-- <br>
Terry Jan Reedy</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</div></div></blockquote></div><br></div>