Switch statement in Swift

后端 未结 7 1575
礼貌的吻别
礼貌的吻别 2020-12-01 01:26

I\'m learning syntax of Swift and wonder, why the following code isn\'t working as I expect it to:

for i in 1...100{

    switch (i){
    case 1:
        Int         


        
相关标签:
7条回答
  • 2020-12-01 02:01

    This is how it can be done

    var i = 0
    
    switch i  {
    
    case i where i % 5 == 0 && i % 3 == 0: print(" Fizz Buzz")
    case i where i % 3 == 0 : print("Fizz")
    case i where i % 5 == 0 : print("Buzz")
    default: print(i)
    
    }
    
    0 讨论(0)
提交回复
热议问题