- Proposal: SE-0666
- Author: Erica Sadun
- Status: Draft
- Review manager: Crusty
This proposal introduces goto to Swift.
In a nutshell, the tl;dr of this is "Mike Ash dared me."
Introducing "goto" permits a one-way transfer of control to another point in code under a common scope. Wikipedia writes: "Many languages support the goto statement, and many do not." Right now Swift does not.
Swift is an opinionated language, and in its opinion, all the effort people go to just to avoid a simple goto places an undue burden on coders, especially on Monday mornings with suboptimal levels of coffee.
- Swift already supports labels for continue and break.
- Labels are extended to any point in code, not just at loops.
- A
gotostatement redirects execution to that label.
label:
...
goto labelThis proposal is purely additive. Theoretically it could break any code that uses goto as a symbol but it's self evident that anyone who has done so deserves to have their code broken.
comefrom is computationally less practical.
Follow-up: Allow storing labels in label references. This enables straightforward implementation of an indirect-threaded interpreter, and would be analogous to the GCC extension "Labels as Values".