diff options
author | Li Jin <dragon-fly@qq.com> | 2025-05-26 11:07:38 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2025-05-26 11:07:38 +0800 |
commit | a91135ce512f907ed085d9aac147d8fcad356406 (patch) | |
tree | e53408fe0a88ef71ea33d14bcb0b6eeb3a344810 /doc/docs/zh | |
parent | 4ba4c90e711c6204aa40e38347c5a5a076d9370e (diff) | |
download | yuescript-a91135ce512f907ed085d9aac147d8fcad356406.tar.gz yuescript-a91135ce512f907ed085d9aac147d8fcad356406.tar.bz2 yuescript-a91135ce512f907ed085d9aac147d8fcad356406.zip |
Added assignment expression for switch syntax.
Diffstat (limited to 'doc/docs/zh')
-rwxr-xr-x | doc/docs/zh/doc/README.md | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 1dd59a7..da90fa6 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
@@ -2655,28 +2655,26 @@ reader\parse_line! until reader\eof! | |||
2655 | 2655 | ||
2656 | ## switch 语句 | 2656 | ## switch 语句 |
2657 | 2657 | ||
2658 | switch语句是为了简化检查一系列相同值的if语句而提供的简写语法。要注意用于比较检查的目标值只会计算一次。和if语句一样,switch语句在最后可以接一个else代码块来处理没有匹配的情况。在生成的Lua代码中,进行比较是使用==操作符完成的。 | 2658 | switch语句是为了简化检查一系列相同值的if语句而提供的简写语法。要注意用于比较检查的目标值只会计算一次。和if语句一样,switch语句在最后可以接一个else代码块来处理没有匹配的情况。在生成的Lua代码中,进行比较是使用==操作符完成的。switch语句中也可以使用赋值表达式来储存临时变量值。 |
2659 | 2659 | ||
2660 | ```moonscript | 2660 | ```moonscript |
2661 | name = "Dan" | 2661 | switch name := "Dan" |
2662 | switch name | ||
2663 | when "Robert" | 2662 | when "Robert" |
2664 | print "你是Robert" | 2663 | print "你是Robert" |
2665 | when "Dan", "Daniel" | 2664 | when "Dan", "Daniel" |
2666 | print "你的名字是Dan" | 2665 | print "你的名字是Dan" |
2667 | else | 2666 | else |
2668 | print "我不知道你的名字" | 2667 | print "我不认识你,你的名字是#{name}" |
2669 | ``` | 2668 | ``` |
2670 | <YueDisplay> | 2669 | <YueDisplay> |
2671 | <pre> | 2670 | <pre> |
2672 | name = "Dan" | 2671 | switch name := "Dan" |
2673 | switch name | ||
2674 | when "Robert" | 2672 | when "Robert" |
2675 | print "你是Robert" | 2673 | print "你是Robert" |
2676 | when "Dan", "Daniel" | 2674 | when "Dan", "Daniel" |
2677 | print "你的名字是Dan" | 2675 | print "你的名字是Dan" |
2678 | else | 2676 | else |
2679 | print "我不知道你的名字" | 2677 | print "我不认识你,你的名字是#{name}" |
2680 | </pre> | 2678 | </pre> |
2681 | </YueDisplay> | 2679 | </YueDisplay> |
2682 | 2680 | ||
@@ -3484,13 +3482,13 @@ me = create_person "Leaf", [dad, mother, sister] | |||
3484 | 如果你想给表达式另外起一个名称的话,with语句中的表达式也可以是一个赋值语句。 | 3482 | 如果你想给表达式另外起一个名称的话,with语句中的表达式也可以是一个赋值语句。 |
3485 | 3483 | ||
3486 | ```moonscript | 3484 | ```moonscript |
3487 | with str = "你好" | 3485 | with str := "你好" |
3488 | print "原始:", str | 3486 | print "原始:", str |
3489 | print "大写:", \upper! | 3487 | print "大写:", \upper! |
3490 | ``` | 3488 | ``` |
3491 | <YueDisplay> | 3489 | <YueDisplay> |
3492 | <pre> | 3490 | <pre> |
3493 | with str = "你好" | 3491 | with str := "你好" |
3494 | print "原始:", str | 3492 | print "原始:", str |
3495 | print "大写:", \upper! | 3493 | print "大写:", \upper! |
3496 | </pre> | 3494 | </pre> |