Idiom for consecutive loops?

Harald Kirsch kirschh at lionbioscience.com
Mon Aug 6 08:08:31 EDT 2001


When programming in C I find myself writing consecutive loops like

  for(i=0; i<lastI; i++) {
    justDoIt(i);
    if( someTest(i) ) break;
  }
  /* the next loop continues were the last one stopped */
  for(/**/; i<lastI; i++) {
    doSomethingElse(i);
  }       

The nice thing is that this is safe even if someTest never becomes
true in the first loop.

How would I do that in python, in particular when looping over list
elements rather than just over numbers.

  Harald Kirsch
P.S.: Please no `while 1:' solutions. I hate them.

-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list