Skip to content

Instantly share code, notes, and snippets.

@mtavkhelidze
Created July 8, 2018 17:23
Show Gist options
  • Save mtavkhelidze/f1f78af8ea2de75d924b5cac18e72667 to your computer and use it in GitHub Desktop.
Save mtavkhelidze/f1f78af8ea2de75d924b5cac18e72667 to your computer and use it in GitHub Desktop.
Mimicking loops in Scala
import scala.language.reflectiveCalls
def repeat(command: => Unit) = new {
def until(condition: => Boolean): Unit =
if (condition) {
command
until(condition)
} else ()
}
var x = 10
repeat {
println(x)
x = x - 1
} until (x > 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment