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! μμ ;μ μμ νμΈμ.