<p dir="ltr"><br>
On 25 Jun 2013 00:31, "alex23" <<a href="mailto:wuwei23@gmail.com">wuwei23@gmail.com</a>> wrote:<br>
><br>
> On 25/06/2013 6:12 AM, Ian Kelly wrote:<br>
>><br>
>> On Mon, Jun 24, 2013 at 1:52 PM,  <<a href="mailto:jimjhb@aol.com">jimjhb@aol.com</a>> wrote:<br>
>>><br>
>>> Syntax:<br>
>>> fwhile X in ListY and conditionZ:<br>
>>><br>
>>> fwhile would act much like 'for', but would stop if the condition after the<br>
>>> 'and' is no longer True.<br>
>><br>
>><br>
>> I would advocate using the break myself.  Another alternative is this:<br>
>><br>
>> for X in itertools.takewhile(lambda X: conditionZ, ListY):<br>
>>      ...<br>
><br>
><br>
> I'd probably just go with a generator expression to feed the for loop:<br>
><br>
>     for X in (i for i in ListY if conditionZ):<br>
>         ....</p>
<p dir="ltr">That is nice but it's not lazy. If the condition or the iterables took too long to compute, it would be troublesome.</p>