question about for cycle
duncan.booth at invalid.invalid
Mon Oct 1 09:46:32 CEST 2007
"fdu.xiaojf at gmail.com" <fdu.xiaojf at gmail.com> wrote:
>>> Sometime it maybe a waste to generate all possible combinations of
>>> i,j first.
>> It doesn't; read about generator expressions at
> Thanks, I didn't realize that.
> However, I still think labeled break and continue is a valuable
> feature, which is easier to understand and to use.
Can you come up with a realistic example where you think a labelled break
would be easier to understand and use? A concrete example would really help
if you hope to persuade anyone that your way is better.
I find that Python's ability to extract the control part of a loop into a
generator is an extremely powerful way to make loops much clearer for
several reasons: you separate completely the 'what we are looping over',
and 'when do we stop' from the 'what do we then do with each item'; also
you have an opportunity to give the code controlling the loop a separate
(and meaningful) name.
More information about the Python-list