# "fallthrough" + "guard/else"

**URL:** <https://forums.swift.org/t/fallthrough-guard-else/72680>\
**Category:** Using Swift\
**Tags:** switch, guard\
**Created:** [June 23, 2024, 6:59am UTC](https://forums.swift.org/t/fallthrough-guard-else/72680 "2024-06-23T06:59:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoBo-Inc](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/robo-inc/32/34319_2.png) [@RoBo-Inc](https://forums.swift.org/u/RoBo-Inc)\
**Post date:** [June 23, 2024, 6:59am UTC](https://forums.swift.org/t/fallthrough-guard-else/72680/1 "2024-06-23T06:59:41Z")

</div>

Can anybody please confirm, that this usage of "fallthrough" is eligible? 🙏 (the code compiles)

```swift
extension URLRequest {
    init(url: URL, httpMethod: HTTPMethod, token: String? = nil) {
        switch httpMethod {
        case .post(let body), .put(let body?):
            guard let httpBody = try? body.encode() else { fallthrough }
            self.init(url, httpMethod.name, httpBody, "application/json", token)
        default:
            self.init(url, httpMethod.name, nil, nil, token)
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [June 23, 2024, 8:13am UTC](https://forums.swift.org/t/fallthrough-guard-else/72680/2 "2024-06-23T08:13:01Z")

</div>

(EDITIED) It looks like the `fallthrough` here has nothing to do with `guard/else` here. `fallthrough` is used to jump to the next `case` block, and since it jumps out of the current context, `guard/else` accepts it (just like `return` in a `func`).

---

<div class="post-metadata">

**Author:** ![jpmhouston](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jpmhouston/32/4045_2.png) [@jpmhouston](https://forums.swift.org/u/jpmhouston)\
**Post date:** [August 12, 2025, 10:34pm UTC](https://forums.swift.org/t/fallthrough-guard-else/72680/3 "2025-08-12T22:34:57Z")

</div>

Late to this discussion, but I hope this helps someone:

I wound up on this year-old thread by searching the web for: “swift switch guard fallthrough”. Like most other information on the web (and like Apple’s documentation?) there’s very little in depth and exhaustive, just minimalist, for-beginners, simplest use cases only. (At least Apple’s pages aren't endless similar AI regurgitations, yet)

I was wondering the same thing as @RoBo-Inc. In my situation in a switch statement over the results of an alert’s `runModal()`, a case for the first button and a default for cancel. I wanted to verify that I could use `guard` / `fallthrough` in an error condition in the first case, it's something I'd never had the occasion to do before.

I don’t think “`fallthrough` here has nothing to do with `guard/else` here” is a helpful answer. The original question with respect to the two constructs is a valid one, if `fallthrough` was okay to use as control flow in the `else` clause of a `guard` for exiting the current scope, like break or return, etc.

And although it doesn't seem to be terribly explicit in the documentation or covered in many examples or discussions online, yes it's indeed okay to use `fallthrough` here, and that it does what you expect.

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 13, 2025, 4:49pm UTC](https://forums.swift.org/t/fallthrough-guard-else/72680/5 "2025-08-13T16:49:42Z")

</div>

Yes, `fallthrough` anywhere within a `case` will transfer control to the following case block.
