15 lines
335 B
Plaintext
15 lines
335 B
Plaintext
fn main() -> i64 {
|
|
// if 作为表达式: let x = if cond { val1 } else { val2 }
|
|
let a = if true { 10; } else { 20; };
|
|
print_i64(a); // 10
|
|
|
|
let b = if false { 10; } else { 20; };
|
|
print_i64(b); // 20
|
|
|
|
// 嵌套 if 表达式
|
|
let c = if a > 5 { 100; } else { 0; };
|
|
print_i64(c); // 100
|
|
|
|
return 0;
|
|
}
|