# Inferred return for guard statement

**URL:** <https://forums.swift.org/t/inferred-return-for-guard-statement/12099>\
**Category:** Pitches\
**Created:** [April 24, 2018, 8:20am UTC](https://forums.swift.org/t/inferred-return-for-guard-statement/12099 "2018-04-24T08:20:48Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![benrimmington](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/benrimmington/32/695_2.png) [@benrimmington](https://forums.swift.org/u/benrimmington)\
**Post date:** [April 24, 2018, 5:21pm UTC](https://forums.swift.org/t/inferred-return-for-guard-statement/12099/11 "2018-04-24T17:21:35Z")

</div>

> [@\[Pitch\] Allow alternate version of 'Guard' with 'Guards'](https://forums.swift.org/t/pitch-allow-alternate-version-of-guard-with-guards/9049):
>
> Proposing an alternate of guard named guards that implicitly returns out of the function and would supply nil if an optional return was declared. This would be purely for the sake of brevity yet still allow for the more explicit guard version to be used. example: guard requiredObject != nil else { return } or guard requiredObject != nil else { return nil } becomes: guards requiredObject != nil but still allows for: guard requiredObject != nil else { // track analytic event or log case …

> [@An implicit return for guard](https://forums.swift.org/t/an-implicit-return-for-guard/3043):
>
> Dear community, While using ‘guard’ with much appreciation, I noticed a few cases where I would of hoped for better and more concise code. As of now, you receive a compiler error if your guard statement does not provide an ending statement such as return/break/etc. at the end. It is informative, but in many cases such a statement makes the code repetitive and less concise. As an example of cases where there are multiple guards done sequentially to avoid very nested and unclear ‘if's: gu…

> [@Guard Implicit Fallback](https://forums.swift.org/t/guard-implicit-fallback/1392):
>
> Hey everyone, I feel that `guard` could be a little more Swifty and would like to start a conversation concerning it. For example, I often have a function whose job depends on an optional having a value, and so I guard-let at the start and return if the guard fails. Or if the function returns an optional type, I'll simply return nil if guard fails. Can we improve on the general fallback case? Could we simply say: func noReturn() { &nbsp;&nbsp;&nbsp;&nbsp;guard let aValue = someOptional &nbsp;&nbsp;&nbsp;&nbsp;.... } and ha…

> [@Proposal: Add implicit/default else-behaviour for the guard statement](https://forums.swift.org/t/proposal-add-implicit-default-else-behaviour-for-the-guard-statement/558):
>
> I find myself writing the same else blocks for guard statements over and over again, so it might be reasonable to think about a default behaviour. In a current project I found 217 guard statements from which 183 have repetitive else clauses From which: 131 end with "else { return nil }" 44 "else { return }" 6 "else { continue }" 2 "else { break }" My proposal would be to make the else block optional and define a default behaviour. For example: func foo(x: Int) { ​ ​ guard x \< …

---

_[View the full topic](https://forums.swift.org/t/inferred-return-for-guard-statement/12099)._
