Swift 基础教程:repeat-while 循环

repeat-while 是在 Swift 中才有, Objective-C 时代没有的。
repeat-while 和其他语言的 do-while 类似。

var index = 10
repeat {
    print(index)
}while index < 8
// 10

while index < 10 {
    print(index)
}
// 无输出

不管何种情况 repeat 肯定会执行一次,然后判断循环条件,这与 while 循环刚好相反,这在使用时需要注意。

猜你喜欢

转载自blog.csdn.net/yao1500/article/details/106257025