Android/Kotlin
When 문
컴공 윤서혜 학습일기
2021. 7. 2. 11:24
when(x) {
1 -> print("X==1")
2 -> print("X==2")
else -> {
print("X is neither 1 nor 2")
}
}
when(x){
0,1 -> print("X==0 or X==1")
else -> print("otherwise")
}
when(x){
in 1..10 -> print("X는 1부터 10 범위 안에 있음")
!in 10..20 ->print("X는 10부터 20 범위 안에 없음")
else -> print("otherwise")
}
when(x){
is Int -> print("x는 인트형")
else -> print("X는 인트형이 아님")
}
다음과 같이 Switch문이 없는 대신에 When문이 있습니다.