swift中的switch case语句中,多个case放在一起的写法,不是:
switch xxx{ case 1: case 2: yyyy }
官网的:
let anotherCharacter: Character = "a" switch anotherCharacter { case "a": case "A": print("The letter A") default: print("Not the letter A") } // this will report a compile-time error
搜:
swift for in range
参考官网:
而是:
switch some value to consider { case value 1, value 2: statements }
而类似于continue,则用fallthrough:
let integerToDescribe = 5 var description = "The number \(integerToDescribe) is" switch integerToDescribe { case 2, 3, 5, 7, 11, 13, 17, 19: description += " a prime number, and also" fallthrough default: description += " an integer." } print(description) // prints "The number 5 is a prime number, and also an integer."
[总结]
swift中switch的多个case在一起,则用逗号分隔开即可;
而如果想要实现类似于continue的效果,则加上fallthrough。
转载请注明:在路上 » [已解决]swift中switch和case中多个case放在一起以及类似于continue如何写