switch
switch must be exhaustive and does not fall through. Cases can match ranges, tuples and conditions.
Example
let n = 7
switch n {
case 1, 2: print("small")
case 3...9: print("medium")
case let x where x > 100: print("huge \(x)")
default: print("other")
}Exercise
Default case.
: print("x")Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.