Foggy day
Kotlin - when, for 본문
val list = listOf<Int>(3, 4, 5, 6, 7, 8, 9, 10)
val value = 12
val result = when (value) {
in list -> "value is in the list"
in 1..10 -> "It is in the range A"
in 10..20 -> "It is in the range B"
else -> "none fo the above"
}
println("result : $result")
//result : It is in the range B
val array = arrayOf("A", "B", "C", "D")
for (i in array.indices) {
println("i : ${array[i]}")
}
// A, B, C, D
for ((index, value) in array.withIndex()) {
println("index : $index, value : $value")
}
'Kotlin' 카테고리의 다른 글
Kotlin - data class destructuring (0) | 2021.04.08 |
---|---|
Kotlin - Object Expressions (0) | 2021.04.08 |
Kotlin - recursive function -2 : TCE (0) | 2021.03.21 |
Kotlin - recursive function -1 (0) | 2021.03.21 |
Kotlin - lambda expression -5 : using data class, value type (0) | 2021.03.21 |