<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
(re-posting here as I first mistakenly answered directly to Terry.
Sorry about that!)<br>
Le 10/08/17 à 22:03, Terry Reedy a écrit :<br>
<div class="moz-cite-prefix">
<blockquote type="cite" cite="mid:omie6o$jf2$1@blaine.gmane.org">
[...]<br>
result = [] <br>
for x in sequence: <br>
if condition: <br>
result.append(expression) <br>
else: <br>
break <br>
<br>
which could be written <br>
<br>
[expression for x in sequence if condition break] <br>
<br>
</blockquote>
It's what I thought too. Adding a `while` clause here just overly
complicates the understanding of the comprehension. The `break`
keyword is already easily understandable and helps to map the
comprehension with the plain for-loop (I like this mapping for its
reverse counterpart, as I often start with plain for-loops to
rewrite them later to comprehensions when it makes sense).<br>
I would probably suggest this instead of Terry's proposal, though:<br>
<tt>[expression for x in sequence if condition</tt><tt><b> or </b></tt><tt>break]</tt><br>
(maybe it's what you meant?).<br>
I suggest this because it doesn't imply the execution of a
statement inside the comprehension, but just to continue the
evaluation as it's always done.<br>
I admit it feels a bit hacky, but maybe just until we get used to
it?<br>
<br>
-Brice</div>
</body>
</html>