아래 코드를
while (...) {
when (itemType) {
1 -> continue
else -> break
}
}
이렇게 수정해줍니다.
loop@ while (...) {
when (itemType) {
1 -> continue@loop
else -> break@loop
}
}
@label을 사용하는 이유
Any expression in Kotlin may be marked with a label.
Labels have the form of an identifier followed by the @ sign, for example: abc@, fooBar@ are valid labels(...) A break qualified with a label jumps to the execution point right after the loop marked with that label. A continue proceeds to the next iteration of that loop.
How to `continue` or `break` in a `when` statement inside a `while` loop using Kotlin
I am converting a large project to Kotlin. There have been numerous challenges. Me learning the new patterns of Kotlin is one of them. Hopefully there is a pattern I can use to resolve this one. ...
stackoverflow.com
'OLD_달려라 > Android' 카테고리의 다른 글
개인 프로젝트 ] (Solved) EditText에서 검색 리스트 보여주기 (0) | 2021.01.27 |
---|---|
개인 프로젝트 ] API (0) | 2021.01.27 |
Log 작성] Logcat을 이용한 로그 작성 및 보기 (0) | 2021.01.15 |
개인 프로젝트 ] (Solved)ListView problem (0) | 2021.01.11 |
개인 프로젝트 ] (Solved) RecyclerView + AsyncTask problem (0) | 2021.01.11 |
댓글