docs: 重构循环和条件语句的命名
- 将 loop 语句中的 initializer 改为 init - 将 condition 改为 cond - 将 update 改为 step - 更新了相关文档和示例代码
This commit is contained in:
parent
e18d7426bc
commit
e2896eb37d
@ -391,11 +391,11 @@ module: Math
|
|||||||
body:
|
body:
|
||||||
declare num1:int = 1
|
declare num1:int = 1
|
||||||
loop:
|
loop:
|
||||||
initializer:
|
init:
|
||||||
declare counter:int = 1
|
declare counter:int = 1
|
||||||
condition:
|
cond:
|
||||||
counter <= n
|
counter <= n
|
||||||
update:
|
step:
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
body:
|
body:
|
||||||
num1 = num1 * counter
|
num1 = num1 * counter
|
||||||
|
|||||||
@ -102,14 +102,14 @@ x = y + 1
|
|||||||
if 语句的形式如下,else 是可选的:
|
if 语句的形式如下,else 是可选的:
|
||||||
|
|
||||||
```snow
|
```snow
|
||||||
if condition then
|
if cond then
|
||||||
// 条件成立执行的代码
|
// 条件成立执行的代码
|
||||||
else
|
else
|
||||||
// 以上条件不成立执行的代码
|
// 以上条件不成立执行的代码
|
||||||
end if
|
end if
|
||||||
```
|
```
|
||||||
|
|
||||||
condition 可以是表达式(结果为 bool 类型)或者 bool 字面量
|
cond 可以是表达式(结果为 bool 类型)或者 bool 字面量
|
||||||
|
|
||||||
例:
|
例:
|
||||||
|
|
||||||
@ -134,14 +134,14 @@ end module
|
|||||||
loop 语句的形式如下:
|
loop 语句的形式如下:
|
||||||
```snow
|
```snow
|
||||||
loop:
|
loop:
|
||||||
initializer:
|
init:
|
||||||
// 循环开始前可声明循环变量,有且只能声明一个
|
// 循环开始前可声明循环变量,有且只能声明一个
|
||||||
declare i: int = 1
|
declare i: int = 1
|
||||||
condition:
|
cond:
|
||||||
// 循环条件,成立则执行 body 的代码,
|
// 循环条件,成立则执行 body 的代码,
|
||||||
// 不成立则退出循环,有且只能写一条
|
// 不成立则退出循环,有且只能写一条
|
||||||
i <= 100
|
i <= 100
|
||||||
update:
|
step:
|
||||||
// 循环体执行完后执行的代码,有且只能写一条
|
// 循环体执行完后执行的代码,有且只能写一条
|
||||||
i = i + 1
|
i = i + 1
|
||||||
body:
|
body:
|
||||||
@ -158,11 +158,11 @@ module: Main
|
|||||||
body:
|
body:
|
||||||
declare sum: int = 0
|
declare sum: int = 0
|
||||||
loop:
|
loop:
|
||||||
initializer:
|
init:
|
||||||
declare i: int = 1
|
declare i: int = 1
|
||||||
condition:
|
cond:
|
||||||
i <= 100
|
i <= 100
|
||||||
update:
|
step:
|
||||||
i = i + 1
|
i = i + 1
|
||||||
body:
|
body:
|
||||||
sum = sum + i
|
sum = sum + i
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user