for-in 循环
for index in var {
循环体
}
import Cocoa
for index in 1...5 {
print("\(index) 乘于 5 为:\(index * 5)")
}
import Cocoa
var someInts:[Int] = [10, 20, 30]
for index in someInts {
print( "index 的值为 \(index)")
}
while循环
while condition
{
statement(s)
}
import Cocoa
var index = 10
while index < 20
{
print( "index 的值为 \(index)")
index = index + 1
}
repeat...while 循环
repeat
{
statement(s);
}while( condition );
import Cocoa
var index = 15
repeat{
print( "index 的值为 \(index)")
index = index + 1
}while index < 20
循环控制语句
- continue
- break