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! ์•ž์˜ ;์„ ์‚ญ์ œํ•˜์„ธ์š”.