Merge branch 'gh-pages' into feature/Ch-Closures

This commit is contained in:
chenxi
2021-06-22 07:49:53 +08:00
4 changed files with 15 additions and 10 deletions

View File

@ -37,7 +37,7 @@ Swift 中数组的完整写法为 `Array<Element>`,其中 `Element` 是这个
你可以使用构造语法来创建一个由特定数据类型构成的空数组:
```swift
var someInts = [Int]()
var someInts: [Int] = []
print("someInts is of type [Int] with \(someInts.count) items.")
// 打印“someInts is of type [Int] with 0 items.”
```
@ -473,7 +473,7 @@ Swift 的字典使用 `Dictionary<Key, Value>` 定义,其中 `Key` 是一种
你可以像数组一样使用构造语法创建一个拥有确定类型的空字典:
```swift
var namesOfIntegers = [Int: String]()
var namesOfIntegers: [Int: String] = [:]
// namesOfIntegers 是一个空的 [Int: String] 字典
```

View File

@ -97,6 +97,8 @@ for tickMark in stride(from: 3, through: hours, by: hourInterval) {
}
```
以上示例使用 `for-in` 循环来遍历范围、数组、字典和字符串。你可以用它来遍历任何的集合,包括实现了 [Sequence](https://developer.apple.com/documentation/swift/sequence) 协议的自定义类或集合类型。
## While 循环 {#while-loops}
`while` 循环会一直运行一段语句直到条件变成 `false`。这类循环适合使用在第一次迭代前迭代次数未知的情况下。Swift 提供两种 `while` 循环形式: