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

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

Donn Felker

3 года назад

3,369 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@alexandersobolev5284
@alexandersobolev5284 - 29.06.2022 20:05

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.

Ответить
@Lussamguru
@Lussamguru - 15.10.2021 11:17

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

Ответить
@hi-s
@hi-s - 22.07.2021 00:34

awesome content

Ответить