Skip to content

Commit eb47051

Browse files
authored
Merge pull request #2 from CoderArcher/master
Agree merge
2 parents 6bfeb2b + d17dc2e commit eb47051

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

for/main.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,31 @@ for i in 0...10 {
163163
print(rs)
164164

165165

166+
/* --- 2017.07.12 更新 */
167+
/* 0 ~ 50 的遍历 跨步 10
168+
此种方法相当于遍历开区间 0..<50, [0,50) 不会遍历最后一个数
169+
用法常见对数组的遍历,可防止数组取值越界
170+
*/
171+
for i in stride(from: 0, to: 50, by: 10) {
172+
print("i = \(i)")
173+
}
166174

175+
/* 0 ~ 20 的遍历 跨步 5
176+
此种方法相当于遍历 0..<50 [0,50] 闭区间 会遍历最后一个数
177+
*/
178+
for j in stride(from: 0, through: 20, by: 5) {
179+
print("j = \(j)")
180+
}
167181

168-
182+
/*
183+
遍历元组 (实际跟遍历字典类似)
184+
*/
185+
let tupleArray = [("zhangShang",60,170.0),
186+
("liSi",77,175.0),
187+
("wangWu",80,180.0)]
188+
for t in tupleArray {
189+
print("name : \(t.0), weight : \(t.1), height : \(t.2)")
190+
}
169191

170192

171193

0 commit comments

Comments
 (0)