Skip to content

Instantly share code, notes, and snippets.

@metasim
Created November 16, 2013 18:31
Show Gist options
  • Save metasim/7503601 to your computer and use it in GitHub Desktop.
Save metasim/7503601 to your computer and use it in GitHub Desktop.
Example of creating a `repeat { ... } until (...)` like control structure.
import scala.annotation.tailrec
object controls {
def repeat(body: => Unit) = new {
@tailrec
def until(condition: => Boolean) {
body
if (condition) () else until(condition)
}
}
var i = 0;
repeat {
println("i = " + i)
i = i + 1
} until (i > 3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment