코틀린 when in

ALL

Kotlin 범위 조건 when in 사용 방법 예제

숫자나 점수 등을 처리할 때 10부터 30은 A, 40부터 50은 B등 범위를 설정해, 설정된 범위에 해당하면 지정한 값을 출력하고 싶은 경우가 있습니다. 조건문 when과 범위를 지정하는 in을 사용해서 범위 지정을 하는 예제를 보겠습니다. import com.sun.org.apache.xpath.internal.operations.Bool fun score(value: Int) { when(value) { in 0..59 -> println("노력하세요.") in 60..79 -> println("잘했습니다.") in 80..1...