Last active
September 20, 2019 08:22
-
-
Save sgabber/f264c9770a0ef4a7345c514560b988b4 to your computer and use it in GitHub Desktop.
implementing the repeat until (like do while) only with basic scala constructs
This file contains hidden or 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
object RepeatTest { | |
class RepeatHelper(cmd: => Unit) { | |
def until(cond: => Boolean): Unit = if (cond) repeat(cmd) | |
} | |
def repeat(cmd: => Unit): RepeatHelper = { | |
cmd | |
new RepeatHelper(cmd) | |
} | |
def main(args: Array[String]): Unit = { | |
var x = 3 | |
repeat {x = x - 1; println(x)} until (x > 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment