Advertisement
Guest User

1

a guest
Jul 20th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.47 KB | None | 0 0
  1. // Выполнено плохо. Мутабельная переменная и цикл вместо рекурсии
  2. object Run {
  3.  
  4.   def run(body: => Unit) = new {
  5.     def until(condition: Unit => Boolean): Unit = {
  6.       var value = body
  7.       while (!condition(value)) {
  8.         value = body
  9.       }
  10.       value
  11.     }
  12.   }
  13.  
  14.   def main(args: Array[String]): Unit = {
  15.     val value = run {
  16.       Random.nextInt(10)
  17.     } until (_ == 0)
  18.     println(value);
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement