Re: question about for cycle



On Sep 29, 8:19 am, George Sakkis <george.sak...@xxxxxxxxx> wrote:
On Sep 29, 10:34 am, "fdu.xia...@xxxxxxxxx" <fdu.xia...@xxxxxxxxx>
wrote:



tokl...@xxxxxxxxx wrote:

> On 29 sep, 12:04, "fdu.xia...@xxxxxxxxx" <fdu.xia...@xxxxxxxxx> wrote:

>> for i in generator_a: # the first "for" cycle
>> for j in generator_b:
>> if something_happen:
>> # do something here ..., I want the outer cycle to break
>> break

> Do you like this?

> generator_ab = ((x, y) for x in generator_a for y in generator_b)
> for i, j in generator_ab:
> if condition:
> # do something
> break

In this case, the tuple generator_ab must be generated first.
George

You can get specific break points by expanding the for loop into a
while loop, and this is perhaps why it has never been implemented with
for loops.
ctr_a=0
ctr_b=0
while ctr_a < len(generator_a):
this_el_a = generator_a[ctr_a]

while ctr_b < len(generator_b):
this_el_b = generator_b[ctr_ b]
if something_happen:
ctr_b = len(generator_b) ## break this loop
if something_else:
ctr_a = len(generator_a) ## break outer while loop
ctr_b += 1
ctr_a += 1

.



Relevant Pages

  • Re: To FETCH or NOT
    ... I need to make fieldto be the text in fieldwith out the punctuation ... and loop thru the field and create a new fieldand update it. ... George ... "Al Reid" wrote in message ...
    (microsoft.public.vb.database.ado)
  • Re: populating arrays
    ... George wrote: ... I moved it outside the loop, and the values of u produce on two successive runs are listed below. ... I reseeded to show nonrandom behavior. ... It seems that what you have demonstrated is that the first random number in the sequence doesn't change very much when the generator is reseeded using a time of day based seed that hasn't really changed very much. ...
    (comp.lang.fortran)
  • Re: error "There is not enough memory available now."
    ... "George" schrieb im Newsbeitrag ... > I've seen a number of posts to this error message, ... I tried to set ulimit -s ... If you change the for loop to a while loop it will work with ksh88, ...
    (comp.unix.aix)
  • Re: Macro Stepping
    ... If you hover your mouse pointer over the variable name you'll see the ... George wrote: ... loop) is it possible to "see" the current values. ...
    (microsoft.public.excel.programming)
  • Pete Rock just beat me to it....
    ... Listening to some jazz records I just picked up, and from George Benson's "Face it Boy, it's Over"....i hear the loop from "I get ...
    (rec.music.hip-hop)