Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Loops-Do-while/Scala/loops-do-while-1.scala
Normal file
8
Task/Loops-Do-while/Scala/loops-do-while-1.scala
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
var (x, l) = (0, List[Int]())
|
||||
do {
|
||||
x += 1
|
||||
l :+= x // A new copy of this list with List(x) appended.
|
||||
} while (x % 6 != 0)
|
||||
l
|
||||
}.foreach(println(_))
|
||||
6
Task/Loops-Do-while/Scala/loops-do-while-2.scala
Normal file
6
Task/Loops-Do-while/Scala/loops-do-while-2.scala
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def loop(iter: Int, cond: (Int) => Boolean, accu: List[Int]): List[Int] = {
|
||||
val succ = iter + 1
|
||||
val temp = accu :+ succ
|
||||
if (cond(succ)) loop(succ, cond, temp) else temp
|
||||
}
|
||||
println(loop(0, (_ % 6 != 0), Nil))
|
||||
5
Task/Loops-Do-while/Scala/loops-do-while-3.scala
Normal file
5
Task/Loops-Do-while/Scala/loops-do-while-3.scala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def loop(i: Int, cond: (Int) => Boolean): Stream[Int] = {
|
||||
val succ = i + 1;
|
||||
succ #:: (if (cond(succ)) loop(succ, cond) else Stream.empty)
|
||||
}
|
||||
loop(0, (_ % 6 != 0)).foreach(println(_))
|
||||
Loading…
Add table
Add a link
Reference in a new issue