控制流 / 条件语句 / switch/case 语句

func getMonitorSize() -> Int {
    return (14...27).randomElement()!
}

let inchSize = getMonitorSize()
let str = switch inchSize {
    case 14,15:
    "too small"
    case 16,17,18:
    "good for the past decade"
    case 19...23:
    "for office work"
    case 24..<28:
    "great choice"
    default:
    ""
}

print("Monitor \(inchSize)\" is \(str)")


Swift provides a shorthand spelling of switch that you can use when setting values.