Switch fallthroughs
suggest changeSwift ends each case with an implicit break. Other languages often fall through unless you write break. To run the next case's body as well, use fallthrough. It does not test the next pattern; it runs that body unconditionally.
let value = "one"
switch value {
case "one":
// do operation one
fallthrough
case "two":
// runs for "two", and also after the "one" case because of fallthrough
break
default:
// default operation
break
}
This is useful for layered handling, such as a stream of states.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents