Swift - for循环/repeat-while循环
2017-03-14 本文已影响88人
GA_
别看我 我只是过往云烟
swift 3.0
// for-each循环
(1...10).forEach {
print($0)
}
// 反转
for i in (1...10).reversed() {
print(i)
}
let array = [1, 5, 3, 2, 4]
// 遍历
for (index, value) in array.enumerated() {
print("\(index + 1) \(value)")
}
let numberOfLegs = [“spider” : 8, “cat” : 4]
for (animalName, legCount) in numberOfLegs {
print(animalName, legCount)
}
for i in 0 ..< attributes.count{
}
attributes.count 等于 2 打印出来 0 1
attributes.count 等于 3 打印出来 0 1 2
for var i = 0 ; i<5 ;i++ {
println("i=\(i)")
}
for temp in [temp] {
}
for (int i = 0; i < 10; i++) {
}
for var index = 0; index < 3; ++index {
print(index)
}
//
var count: Int = 0
repeat {
print("我是repeat")
count++
} while count < 5
print("END")