class Looper { fun doIteration() { //run loop until the next call to yield, then return from this function } fun loop() { for (i in 0 until 10) { println(i) yield() } } } fun main(args: Array) { val looper = Looper() looper.doIteration() //prints "0" looper.doIteration() //prints "1" }