<p>What is the Python equivalent of the following code in Ruby?</p>

<pre><code>def loop
  cont=nil
  for i in 1..4
    puts i
    callcc {|continuation| cont=continuation} if i==2
  end
  return cont
end

&gt; c=loop
1
2
3
4
&gt; c.call
3
4
</code></pre>

<p>Reference: <a href="http://www-128.ibm.com/developerworks/java/library/os-lightweight9/" rel="nofollow noreferrer">Secrets of lightweight development success, Part 9: Continuations-based frameworks</a></p>

take a look at the
yield
statement to make generators.
I don't speak any ruby, but it seems like you're 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 realize this is basically a specialization of real continuations, but it should be sufficient for most purposes. Use
```
yield
```
to return the continuation and the
```
.next()
```
message on the generator (returned by just calling
```
loop()
```
) to reenter.