Kotlin Control Flow
if
fun main() {
    val a = 2
 
    if(a < 0) {
       println("a는 음수")
    } else if (a % 2 == 0) {
        println("a는 짝수")
    } else {
        println("a는 홀수")
    }
}삼항연산자
kotlin에서는 다음과 같은 표현을 condition ? true : fasle을 if(condition) true else false
fun main() {
    val a = 1
    val b = 2
 
    println(if (a > b) a else b) // Returns a value: 2
}범위 연산
fun main() {
    var chr: Char = 'C'
    println(chr in 'a'..'z') // false
}when
kotlin의 switch-case문
- 각 분기에서 
->를 사용해서 각 조건을 구분한다. - break 관련없이 해당되는 첫 번째 조건만 실행된다.
 - 모든 분기에 해당되는 조건이 없으면 
else를 사용한다. - when은 리턴값을 변수에 바로 할당할 수 있다.
 
fun main() {
    val temp = 18
 
    val description = when {
        // If temp < 0 is true, sets description to "very cold"
        temp < 0 -> "very cold"
        // If temp < 10 is true, sets description to "a bit cold"
        temp < 10 -> "a bit cold"
        // If temp < 20 is true, sets description to "warm"
        temp < 20 -> "warm"
        // Sets description to "hot" if no previous condition is satisfied
        else -> "hot"
    }
    println(description)
}when with Enum
enum class Color {
    RED, GREEN, BLUE
}
 
 
fun main() {
    val color: Color = Color.GREEN
    when (color) {
        Color.RED -> println("red")
        Color.GREEN -> println("green")
        Color.BLUE -> println("blue")
        // 'else' is not required because all cases are covered
    }
}Ranges
fun main() {
    for (i in 0..4) print(i) // 01234
    println()
        
    /// 문자형도 가능
    for (i in 'a'..'e') print(i) // abcde
 
    /// 2칸씩
    for (i in 0..<8 step 2) print(i)
    println()  // 0246
 
    /// 2칸씩 내려감
    for (i in 8 downTo 0 step 2) print(i) // 86420
}