个性化阅读
专注于IT技术分析

Swift循环中的控制语句:continue语句用法

点击下载

控制语句在循环中用于更改其正常顺序的执行。当执行离开作用域时, 将破坏在该作用域中自动创建的所有已创建对象。

Swift 4支持的控制语句列表:


继续声明

Swift 4 Continue语句用于停止当前正在执行的语句, 并在循环的下一次迭代开始时重新开始。 Continue语句与for循环, while循环和do … while循环一起使用。

使用” for”循环, continue语句测试条件并增加循环的执行部分。

通过” while”和” do … while”循环, continue语句将程序控制传递给条件测试。

句法:

Swift 4循环的continue语句的语法如下:

continue

Swift 4 Continue语句流程图

快速继续声明

例:

var index = 10

repeat {
   index = index + 1
   if( index == 25 ){
      continue
   }
   print( "Value of index is \(index)")
} while index < 30

输出

Value of index is 11
Value of index is 12
Value of index is 13
Value of index is 14
Value of index is 15
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
Value of index is 21
Value of index is 22
Value of index is 23
Value of index is 24
Value of index is 25
Value of index is 26
Value of index is 27
Value of index is 28
Value of index is 29
Value of index is 30

赞(0)
未经允许不得转载:srcmini » Swift循环中的控制语句:continue语句用法

评论 抢沙发

评论前必须登录!