feat: 表达式作为值 — if/else 和 block 可产生值
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user