Re: question about for cycle
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 29 Sep 2007 11:39:23 GMT
Ant <antroy@xxxxxxxxx> wrote:
On Sep 29, 11:04 am, "fdu.xia...@xxxxxxxxx" <fdu.xia...@xxxxxxxxx>....
wrote:
...
What should I do if I want the outer "for" cycle to continue or break
? If I put a "continue" or "break" in the inner cycle, it has no
effect on the outer cycle.
I guess to an extent it would depend on the exact situation as to
which of these is more suitable. Are there any other recommended
solutions to this?
I think the other Pythonic option you have missed is to convert the nested
for loops into a single loop by writing a generator.
def ranges(limit1, limit2):
range1, range2 = range(limit1), range(limit2)
for i in range1:
for j in range2:
yield i,j
....
for i, j in ranges(10, 10):
... whatever ...
if j==6:
break
.
- References:
- question about for cycle
- From: fdu.xiaojf@xxxxxxxxx
- Re: question about for cycle
- From: Ant
- question about for cycle
- Prev by Date: Re: question about for cycle
- Next by Date: Re: Python 3.0 migration plans?
- Previous by thread: Re: question about for cycle
- Next by thread: Re: question about for cycle
- Index(es):