Since case:
blocks auto-break, Swift provides the fallthrough keyword. This is of limited use because it doesn't fallthrough to the next conditional test, it bypasses the next test and just executes the code from the next test. Is it possible to have a switch statement perform the code in multiple cases while also performing the conditionals?
As an example from the Swift documentation, what if I need the code below to execute every block that applies to the given point?
let somePoint = (0, 0)
switch somePoint {
case (0, 0):
print("\(somePoint) is at the origin")
case (_, 0):
print("\(somePoint) is on the x-axis")
case (0, _):
print("\(somePoint) is on the y-axis")
case (-2...2, -2...2):
print("\(somePoint) is inside the box")
default:
print("\(somePoint) is outside of the box")
}
As written it will print only the first description even though multiple actually apply. Using fallthrough after each test causes every case block to execute.