if ν‘œν˜„μ‹

λ‹€λ₯Έ μ–Έμ–΄μ˜ if λ¬Έκ³Ό λ˜‘κ°™μ΄ if ν‘œν˜„μ‹μ„ μ‚¬μš©ν•©λ‹ˆλ‹€:

fn main() {
    let x = 10;
    if x == 0 {
        println!("zero!");
    } else if x < 100 {
        println!("큰");
    } else {
        println!("κ±°λŒ€ν•œ");
    }
}

κ²Œλ‹€κ°€ ifλŠ” ν‘œν˜„μ‹μœΌλ‘œ μ‚¬μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. μ•„λž˜ μ½”λ“œλŠ” μœ„μ™€ λ™μΌν•©λ‹ˆλ‹€:

fn main() {
    let x = 10;
    let size = if x < 20 { "μž‘μ€" } else { "λŒ€ν˜•" };
    println!("숫자 크기: {}", size);
}
This slide should take about 4 minutes.

Because if is an expression and must have a particular type, both of its branch blocks must have the same type. Show what happens if you add ; after "small" in the second example.

ν‘œν˜„μ‹μ— ’if’가 μ‚¬μš©λœ 경우 λ‹€μŒ λ¬Έκ³Ό κ΅¬λΆ„ν•˜κΈ° μœ„ν•΄ ν‘œν˜„μ‹μ— ;이 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. 컴파일러 였λ₯˜λ₯Ό 보렀면 println! μ•žμ˜ ;을 μ‚­μ œν•˜μ„Έμš”.