본문
170621(수) - Kotlin docs (Return and Jumps)
Mobile/Kotlin 2017. 6. 21. 11:03
Kotlin docs
Return and Jumps
- return
val s = person.name ?: return
- break
- continue
Break and Continue labels
loop@ for (i in 1..100) {
// ...
}
loop@ for (i in 1..100) {
for (j in 1..100) {
if (...) break@loop
}
}
Return at Labels
fun foo() {
ints.forEach {
if (it == 0) return
print(it)
}
}
fun foo() {
ints.forEach lit@ {
if (it == 0) return@lit
print(it)
}
}
fun foo() {
ints.forEach {
if (it == 0) return@forEach
print(it)
}
}
fun foo() {
ints.forEach(fun(value: Int) {
if (value == 0) return
print(value)
})
}
return@a 1
'Mobile > Kotlin' 카테고리의 다른 글
170821(월) - Kotlin docs (Properties and Fields) (0) | 2017.08.21 |
---|---|
170818(금) - Kotlin docs (Classes and Inheritance) (0) | 2017.08.18 |
170619(월) - Kotlin docs (Control Flow) (0) | 2017.06.19 |
170614(수) - Kotlin docs (Packages) (0) | 2017.06.14 |
170607(수) - Kotlin docs (Basic Types) (0) | 2017.05.31 |
댓글