1 import Foundation 2 3 // 数组声明 4 var arr = [String]() 5 // 数组循环添加项 6 for var index in 0...100{ 7 arr.append("Item (index)") 8 } 9 10 // 遍历方法1 11 for item in arr { 12 print (item) 13 } 14 // 遍历方法2 15 for (index, value) in arr.enumerate() { 16 print("Item (index + 1 ) :(value)") 17 } 18 19 print("Hello, World!")
1 var i = 100 2 while i < arr.count{ 3 print(arr[i]) 4 i++ 5 } 6 7 8 print(arr[25])
1 // 字典的遍历 2 var dict = ["name":"jinpangpang","age":"16"] 3 for (key,value) in dict{ 4 print("(key),(value)") 5 }