修正标点与空格错误 (#851)
* 修正 source/chapter2/04_Collection_Types.md 错误的空格与标点 * 修正 source/chapter2/05_Control_Flow.md 错误的空格与标点使用 * 修正 source/chapter2/06_Functions.md 去除多余空格
This commit is contained in:
@ -79,7 +79,7 @@ for tickMark in 0..<minutes {
|
||||
}
|
||||
```
|
||||
|
||||
一些用户可能在其 UI 中可能需要较少的刻度。他们可以每5分钟作为一个刻度。使用 `stride(from:to:by:)` 函数跳过不需要的标记。
|
||||
一些用户可能在其 UI 中可能需要较少的刻度。他们可以每 5 分钟作为一个刻度。使用 `stride(from:to:by:)` 函数跳过不需要的标记。
|
||||
|
||||
```swift
|
||||
let minuteInterval = 5
|
||||
@ -525,11 +525,10 @@ case (let distance, 0), (0, let distance):
|
||||
default:
|
||||
print("Not on an axis")
|
||||
}
|
||||
|
||||
// 输出 "On an axis, 9 from the origin"
|
||||
```
|
||||
|
||||
上面的 case 有两个模式:`(let distance, 0)` 匹配了在 x 轴上的值,`(0, let distance)` 匹配了在 y 轴上的值。两个模式都绑定了 `distance`,并且 `distance` 在两种模式下,都是整型——这意味着分支体内的代码,只要 case 匹配,都可以获取到 `distance` 值
|
||||
上面的 case 有两个模式:`(let distance, 0)` 匹配了在 x 轴上的值,`(0, let distance)` 匹配了在 y 轴上的值。两个模式都绑定了 `distance`,并且 `distance` 在两种模式下,都是整型——这意味着分支体内的代码,只要 case 匹配,都可以获取到 `distance` 值。
|
||||
|
||||
<a name="control_transfer_statements"></a>
|
||||
## 控制转移语句
|
||||
@ -750,7 +749,7 @@ greet(["name": "Jane", "location": "Cupertino"])
|
||||
|
||||
如果 `guard` 语句的条件被满足,则继续执行 `guard` 语句大括号后的代码。将变量或者常量的可选绑定作为 `guard` 语句的条件,都可以保护 `guard` 语句后面的代码。
|
||||
|
||||
如果条件不被满足,在 `else` 分支上的代码就会被执行。这个分支必须转移控制以退出 `guard` 语句出现的代码段。它可以用控制转移语句如 `return`,`break`,`continue` 或者 `throw` 做这件事,或者调用一个不返回的方法或函数,例如 `fatalError()`。
|
||||
如果条件不被满足,在 `else` 分支上的代码就会被执行。这个分支必须转移控制以退出 `guard` 语句出现的代码段。它可以用控制转移语句如 `return`、`break`、`continue` 或者 `throw` 做这件事,或者调用一个不返回的方法或函数,例如 `fatalError()`。
|
||||
|
||||
相比于可以实现同样功能的 `if` 语句,按需使用 `guard` 语句会提升我们代码的可读性。它可以使你的代码连贯的被执行而不需要将它包在 `else` 块中,它可以使你在紧邻条件判断的地方,处理违规的情况。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user