feat: 表达式作为值 — if/else 和 block 可产生值

This commit is contained in:
2026-06-06 13:52:36 +08:00
parent 380b52930a
commit 0ec3c3d65f
4 changed files with 99 additions and 1 deletions
+14
View File
@@ -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;
}