diff options
author | Mark Green <mark@antelope.nildram.co.uk> | 2016-08-14 19:39:07 +0100 |
---|---|---|
committer | Mark Green <mark@antelope.nildram.co.uk> | 2016-08-14 19:39:07 +0100 |
commit | 62102d02992f83b3a1fb745a39f36332dd4435b7 (patch) | |
tree | d5ac79ceac2f61e5658aaa826304d87240a20110 /scala.html.markdown | |
parent | 57053bc95d4166a42da8f6d1732dd21a217b073a (diff) | |
parent | 476de3289df9ef5f72330f3d1359ce9f93d71754 (diff) |
Merge remote-tracking branch 'refs/remotes/adambard/master'
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/scala.html.markdown b/scala.html.markdown index c2aa942c..e82c1c36 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -237,7 +237,7 @@ r foreach println (5 to 1 by -1) foreach (println) -// A while loops +// A while loop var i = 0 while (i < 10) { println("i " + i); i += 1 } @@ -245,17 +245,18 @@ while (i < 10) { println("i " + i); i += 1 } // Yes, again. What happened? Why i // Show the value of i. Note that while is a loop in the classical sense - // it executes sequentially while changing the loop variable. while is very - // fast, faster that Java loops, but using the combinators and - // comprehensions above is easier to understand and parallelize + // fast, but using the combinators and comprehensions above is easier + // to understand and parallelize -// A do while loop +// A do-while loop i = 0 do { println("i is still less than 10") i += 1 } while (i < 10) -// Tail recursion is an idiomatic way of doing recurring things in Scala. +// Recursion is the idiomatic way of repeating an action in Scala (as in most +// other functional languages). // Recursive functions need an explicit return type, the compiler can't infer it. // Here it's Unit. def showNumbersInRange(a: Int, b: Int): Unit = { @@ -273,7 +274,7 @@ val x = 10 if (x == 1) println("yeah") if (x == 10) println("yeah") if (x == 11) println("yeah") -if (x == 11) println ("yeah") else println("nay") +if (x == 11) println("yeah") else println("nay") println(if (x == 10) "yeah" else "nope") val text = if (x == 10) "yeah" else "nope" |