03-Swift 循环的使用

2016-11-16  本文已影响10人  magic_pill

一、for 循环的使用

//MARK : for 循环语句
for i in 1..<5{
    print(i)
}
//打印两遍 test,此时不需要创建变量 i
for _ in 1...2{
    print("test")
}

二、while 循环的使用

//MARK : while 循环
var i = 3
while i>0 {
    print(i)
    i-=1;
}
i = 10
repeat{
    print(i)
    i-=1
}while i>0
上一篇 下一篇

猜你喜欢

热点阅读