Created
July 8, 2018 17:23
-
-
Save mtavkhelidze/f1f78af8ea2de75d924b5cac18e72667 to your computer and use it in GitHub Desktop.
Mimicking loops in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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