if else
if BooleanValue {
}else if BooleanValue2{
}else{
}
switch
不同于很多其它语言,swift并没有break,而是默认就是break
switch value/variable/expression{
case value1:
case value2:
case value3:
default:
}
使用,号同时匹配多个
case 1,2,3:print("The number is 1,2,or 3")
使用…匹配区间
//包括4<= x <= 20
case 4...20:print("The number is betwween 4 and 20")
//包括 4<= x < 20
case 4..<20
枚举
enum dog{
case poodle
case collie
case terrier
case mutt
}
var myPet = dog.collie
switch myPet{
case .poodle:
default:
}