summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaolo Furini <nexbit@users.noreply.github.com>2016-09-12 16:33:16 +0200
committerven <vendethiel@hotmail.fr>2016-09-12 16:33:16 +0200
commit161edb1f6e76a8451d2e74a8fb24d6874f7dab66 (patch)
treee628c85f707bb33c9089e30ce7391a4488a5c6a5
parent71b3342f0434a20eced121764fe2987a292a7745 (diff)
[kotlin/en] Add "if" usage as an expression (#2367)
* [kotlin/en] Add "if" usage as a function * [kotlin/en] Change comment on "if" expression Rephrase the comment to use the term "expression" in place of "function"
-rw-r--r--kotlin.html.markdown8
1 files changed, 8 insertions, 0 deletions
diff --git a/kotlin.html.markdown b/kotlin.html.markdown
index 605b1a63..00182d81 100644
--- a/kotlin.html.markdown
+++ b/kotlin.html.markdown
@@ -261,6 +261,14 @@ fun helloWorld(val name : String) {
ctr++
} while (ctr < 10)
+ /*
+ "if" can be used as an expression that returns a value.
+ For this reason the ternary ?: operator is not needed in Kotlin.
+ */
+ val num = 5
+ val message = if (num % 2 == 0) "even" else "odd"
+ println("$num is $message") // => 5 is odd
+
// "when" can be used as an alternative to "if-else if" chains.
val i = 10
when {