浅谈Swift编程中switch与fallthrough语句的使用

2020-01-08 23:06:10刘景俊

 


Value of index is either 10 or 15

示例 2
以下是 Swift 编程中 switch 语句带有 fallthrough 的例子:

复制代码
import Cocoa

 

var index = 10

switch index {
   case 100  :
      println( "Value of index is 100")
      fallthrough
   case 10,15  :
      println( "Value of index is either 10 or 15")
      fallthrough
   case 5  :
      println( "Value of index is 5")
   default :
      println( "default case")
}


当上述代码被编译和执行时,它产生了以下结果:

 


Value of index is either 10 or 15
Value of index is 5


注:相关教程知识阅读请移步到swift教程频道。