[Python-ideas] if expensive_computation() as x:

Chris Angelico rosuav at gmail.com
Fri Feb 14 09:36:47 CET 2014


On Fri, Feb 14, 2014 at 7:24 PM, spir <denis.spir at gmail.com> wrote:
> But it still assumes all computations and all actions take the same input.
> Else, we're left with unrolling the loop: but how to break outside no loop?
> The solution may be to export the whole series comps/actions into a func and
> return from it.

You can break out of a loop that's guaranteed to execute only once
anyway. In C, that's sometimes spelled "do {......} while (0);", but
in Python you just put a hard break at the end of it. That or 'return'
from a function, either way works.

ChrisA


More information about the Python-ideas mailing list