look at yield to create generators.
I'm not talking about ruby, but it looks like you are looking for this:
def loop(): for i in xrange(1,5): print i if i == 2: yield for i in loop(): print "pass"
Edit: I understand that this is mainly a specialization of real sequels, but this should be enough for most purposes. Use yield to return the continuation and the .next() message on the generator (returned when loop() called) to re-enter.
user40098
source share