Kotlin If/Else Conditional - How to use If/Else in Kotlin

preview_player
Показать описание
In this lesson, you'll learn how an if/else conditional statement works in Kotlin.

Рекомендации по теме
Комментарии
Автор

The best tutorial series on Kotlin ever. You're just so good. You are the best. Thanks for this great content!

Lussamguru
Автор

Great content! I'm watching this series and also reading a book called `Kotlin in action`. And there's one important thing is not mentioned in this video. I don't know maybe it will be mentioned in further videos... Anyways, you can use `if` / `else` as an expression. For example you can assign its result to a variable:
```
val bool = true;

val x = if (bool) {
1
} else {
2
} // x = 1

println(x) // 1
```

PS However, if you use it as an expression, you have to provide the `else` clause, while if you use it as a statement (as in this video), the `else` part can be omitted.
PPS Many other things in Kotlin can be used as expressions, maybe except for `for` loops.

alexandersobolev