无涯教程-Swift - continue 语句函数

47 阅读1分钟

SWIFT 4中的Continue语句告诉循环停止它正在做的事情,并在循环的下一次迭代开始时重新开始。

对于for循环,Continue语句导致条件测试并递增要执行的循环部分,对于While和Do.While循环,Continue语句使程序控制传递给条件测试。

continue - 语法

SWIFT 4中Continue语句语法如下所示:-

continue

continue - 流程图

Continue Statement

continue - 示例

var index=10

repeat { index=index + 1 if( index == 15 ){ continue } print( "Value of index is(index)") } while index < 20

编译并执行上述代码时,将生成以下结果-

Value of index is 11
Value of index is 12
Value of index is 13
Value of index is 14
Value of index is 16
Value of index is 17
Value of index is 18
Value of index is 19
Value of index is 20

参考链接

www.learnfk.com/swift/swift…