0
var index = 30

switch index {

   case 10  :    
      println( "Value of index is 10")
   case 20  :

   case 30  :    
      println( "Value of index is either 20 or 30")
   case 40  :    
      println( "Value of index is 40")
   default :    
      println( "default case")
}
CodeBender
  • 35,668
  • 12
  • 125
  • 132
KSR
  • 1,699
  • 15
  • 22

2 Answers2

5

Fallthrough is allowed in Swift, but you do have to state it explicitly:

switch index {
case 10:
    println( "Value of index is 10")
case 20:
    fallthrough
case 30:
    println( "Value of index is either 20 or 30")
...

For your situation though, it's probably better to just group your cases:

switch index {
case 10:
    println( "Value of index is 10")
case 20, 30:
    println( "Value of index is either 20 or 30")
...
sam-w
  • 7,478
  • 1
  • 47
  • 77
1

Or you can write it this way (Swift 2.2 syntax):

switch index {
case 10:
    print("Value is: \(index)")
case 20, 30:
    print("Value is: \(index)")
default:
    print("Default value is: \(index)")
}
CodeBender
  • 35,668
  • 12
  • 125
  • 132