Switch fallthroughs

suggest change

Swift 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents