for循环
for var i = 0; i < 10; i++ {
print(i)
}
for i in 0..<10 {
print(i)
}
for _ in 0..<10 { //swift里下划线_的作用是忽略
print("hello")
}
while循环
- while的判断句必须有正确的真假,没有非0即真
- while后面的()可以省略
var a = 0
while a < 10 {
a++
}
do while循环
使用repeat关键字来代替了do
let b = 0
repeat {
print(b)
b++
} while b < 20