循环控制

2020-09-16  本文已影响0人  黑白森林无间道

for-in循环

let dict = ["spider": 8, "ant": 6, "cat": 4]
for item in dict {
    print("\(item.0) has \(item.1) legs")
}
for (animalName, legCount) in dict {
    print("\(animalName) has \(legCount) legs")
}

for-in分段区间

for i in stride(from: 0, to: 50, by: 5) {
    print(i)
}
for i in stride(from: 0, through: 50, by: 5) {
    print(i)
}

while循环

var count = 0
repeat {
    print(count)
    count += 1
} while count < 5
上一篇 下一篇

猜你喜欢

热点阅读