SWIFT 4中的Continue语句告诉循环停止它正在做的事情,并在循环的下一次迭代开始时重新开始。
对于for循环,Continue语句导致条件测试并递增要执行的循环部分,对于While和Do.While循环,Continue语句使程序控制传递给条件测试。
SWIFT 4中Continue语句语法如下所示:-
continue
var index=10 repeat { index=index + 1 if( index == 15 ){ continue } print( "Value of index is\(index)") } while index < 20
编译并执行上述代码时,将生成以下结果-
链接:https://www.learnfk.comhttps://www.learnfk.com/swift/swift-continue-statement.html
来源:LearnFk无涯教程网
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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)