別看我 我只是過往云煙
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")
Swift - for循環/repeat-while循環
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
推薦閱讀更多精彩內容
- 1. for循環 1.1 常見的寫法 1.2 for循環中where關鍵字 1.3標簽語句 while循環 rep...
- 三個循環之間的區別 1、for和while是先比較后循環,不滿足就跳出循環 2、do whlie是先循環后比較(不...
- 1.區間運算符 ?閉區間[a,b]-------> a...b?前閉后開區間[a,b)------->a..<b ...
- 循環結構while 和do while 一、是什么? 是指程序循環語句,當條件滿足時進入循環,循環判斷,知道不滿足...