summaryrefslogtreecommitdiff
path: root/README_ZH_CN.md
diff options
context:
space:
mode:
Diffstat (limited to 'README_ZH_CN.md')
-rw-r--r--README_ZH_CN.md30
1 files changed, 19 insertions, 11 deletions
diff --git a/README_ZH_CN.md b/README_ZH_CN.md
index 217e9ec..51689f6 100644
--- a/README_ZH_CN.md
+++ b/README_ZH_CN.md
@@ -485,26 +485,33 @@ match opt {
}
```
-#### 循环
+#### 循環
```zc
-// 区间迭代
-for i in 0..10 { ... } // 左闭右开 (0 到 9)
-for i in 0..<10 { ... } // 左闭右开 (显式)
-for i in 0..=10 { ... } // 全闭 (0 到 10)
+// 區間迭代
+for i in 0..10 { ... } // 左閉右開 (0 到 9)
+for i in 0..<10 { ... } // 左閉右開 (顯式)
+for i in 0..=10 { ... } // 全閉 (0 到 10)
for i in 0..10 step 2 { ... }
-// 迭代器 (Vec, Array, 或自定义 Iterable)
-for item in collection { ... }
+// 迭代器 (Vec 或自定義 Iterable)
+for item in vec { ... }
-// While 循环
+// 直接迭代固定大小数组
+let arr: int[5] = [1, 2, 3, 4, 5];
+for val in arr {
+ // val 是 int
+ println "{val}";
+}
+
+// While 循環
while x < 10 { ... }
-// 带标签的无限循环
+// 帶標籤的無限循環
outer: loop {
if done { break outer; }
}
-// 重复 N 次
+// 重複 N 次
for _ in 0..5 { ... }
```
@@ -606,7 +613,7 @@ Zen C 支持使用 `?` 前缀进行用户输入提示的简写。
- `? "输入年龄: " (age)`: 打印提示并扫描输入到变量 `age` 中。
- 格式说明符会根据变量类型自动推断。
-```c
+```zc
let age: int;
? "你多大了? " (age);
println "你 {age} 岁了。";
@@ -938,6 +945,7 @@ let re = regex! { ^[a-z]+$ };
| `@host` | 函数 | CUDA: 主机函数 (`__host__`)。 |
| `@comptime` | 函数 | 用于编译时执行的辅助函数。 |
| `@derive(...)` | 结构体 | 自动实现 Trait。支持 `Debug`, `Eq` (智能派生), `Copy`, `Clone`。 |
+| `@ctype("type")` | 函数参数 | 覆盖参数生成的 C 类型。 |
| `@<custom>` | 任意 | 将泛型属性传递给 C (例如 `@flatten`, `@alias("name")`)。 |
#### 自定义属性