diff options
Diffstat (limited to '')
| -rwxr-xr-x | doc/docs/zh/doc/README.md | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 7e17b80..a856e7b 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
| @@ -1223,32 +1223,32 @@ for [left, right] in *tuples | |||
| 1223 | 1223 | ||
| 1224 | ## If 赋值 | 1224 | ## If 赋值 |
| 1225 | 1225 | ||
| 1226 | `if` 和 `elseif` 代码块可以在条件表达式的位置进行赋值。在代码执行到要计算条件时,会首先进行赋值计算,并使用赋与的值作为分支判断的条件。赋值的变量仅在条件分支的代码块内有效,这意味着如果值不是真值,那么它就不会被用到。 | 1226 | `if` 和 `elseif` 代码块可以在条件表达式的位置进行赋值。在代码执行到要计算条件时,会首先进行赋值计算,并使用赋与的值作为分支判断的条件。赋值的变量仅在条件分支的代码块内有效,这意味着如果值不是真值,那么它就不会被用到。注意,你必须使用“海象运算符” `:=` 而不是 `=` 来做赋值。 |
| 1227 | 1227 | ||
| 1228 | ```moonscript | 1228 | ```moonscript |
| 1229 | if user = database.find_user "moon" | 1229 | if user := database.find_user "moon" |
| 1230 | print user.name | 1230 | print user.name |
| 1231 | ``` | 1231 | ``` |
| 1232 | <YueDisplay> | 1232 | <YueDisplay> |
| 1233 | <pre> | 1233 | <pre> |
| 1234 | if user = database.find_user "moon" | 1234 | if user := database.find_user "moon" |
| 1235 | print user.name | 1235 | print user.name |
| 1236 | </pre> | 1236 | </pre> |
| 1237 | </YueDisplay> | 1237 | </YueDisplay> |
| 1238 | 1238 | ||
| 1239 | ```moonscript | 1239 | ```moonscript |
| 1240 | if hello = os.getenv "hello" | 1240 | if hello := os.getenv "hello" |
| 1241 | print "你有 hello", hello | 1241 | print "你有 hello", hello |
| 1242 | elseif world = os.getenv "world" | 1242 | elseif world := os.getenv "world" |
| 1243 | print "你有 world", world | 1243 | print "你有 world", world |
| 1244 | else | 1244 | else |
| 1245 | print "什么都没有 :(" | 1245 | print "什么都没有 :(" |
| 1246 | ``` | 1246 | ``` |
| 1247 | <YueDisplay> | 1247 | <YueDisplay> |
| 1248 | <pre> | 1248 | <pre> |
| 1249 | if hello = os.getenv "hello" | 1249 | if hello := os.getenv "hello" |
| 1250 | print "你有 hello", hello | 1250 | print "你有 hello", hello |
| 1251 | elseif world = os.getenv "world" | 1251 | elseif world := os.getenv "world" |
| 1252 | print "你有 world", world | 1252 | print "你有 world", world |
| 1253 | else | 1253 | else |
| 1254 | print "什么都没有 :(" | 1254 | print "什么都没有 :(" |
| @@ -1257,13 +1257,13 @@ else | |||
| 1257 | 1257 | ||
| 1258 | 使用多个返回值的 If 赋值。只有第一个值会被检查,其他值都有同样的作用域。 | 1258 | 使用多个返回值的 If 赋值。只有第一个值会被检查,其他值都有同样的作用域。 |
| 1259 | ```moonscript | 1259 | ```moonscript |
| 1260 | if success, result = pcall -> "无报错地获取结果" | 1260 | if success, result := pcall -> "无报错地获取结果" |
| 1261 | print result -- 变量 result 是有作用域的 | 1261 | print result -- 变量 result 是有作用域的 |
| 1262 | print "好的" | 1262 | print "好的" |
| 1263 | ``` | 1263 | ``` |
| 1264 | <YueDisplay> | 1264 | <YueDisplay> |
| 1265 | <pre> | 1265 | <pre> |
| 1266 | if success, result = pcall -> "无报错地获取结果" | 1266 | if success, result := pcall -> "无报错地获取结果" |
| 1267 | print result -- 变量 result 是有作用域的 | 1267 | print result -- 变量 result 是有作用域的 |
| 1268 | print "好的" | 1268 | print "好的" |
| 1269 | </pre> | 1269 | </pre> |
| @@ -1372,7 +1372,7 @@ try | |||
| 1372 | func 1, 2, 3 | 1372 | func 1, 2, 3 |
| 1373 | 1373 | ||
| 1374 | -- 使用if赋值模式 | 1374 | -- 使用if赋值模式 |
| 1375 | if success, result = try func 1, 2, 3 | 1375 | if success, result := try func 1, 2, 3 |
| 1376 | catch err | 1376 | catch err |
| 1377 | print yue.traceback err | 1377 | print yue.traceback err |
| 1378 | print result | 1378 | print result |
| @@ -1400,7 +1400,7 @@ try | |||
| 1400 | func 1, 2, 3 | 1400 | func 1, 2, 3 |
| 1401 | 1401 | ||
| 1402 | -- 使用if赋值模式 | 1402 | -- 使用if赋值模式 |
| 1403 | if success, result = try func 1, 2, 3 | 1403 | if success, result := try func 1, 2, 3 |
| 1404 | catch err | 1404 | catch err |
| 1405 | print yue.traceback err | 1405 | print yue.traceback err |
| 1406 | print result | 1406 | print result |
