Document break, @label and continue more thoroughly#60818
Open
jakobnissen wants to merge 6 commits intoJuliaLang:masterfrom
Open
Document break, @label and continue more thoroughly#60818jakobnissen wants to merge 6 commits intoJuliaLang:masterfrom
break, @label and continue more thoroughly#60818jakobnissen wants to merge 6 commits intoJuliaLang:masterfrom
Conversation
nsajko
reviewed
Jan 25, 2026
| Because structured control flow is easier to reason about than goto statements, | ||
| goto statements should generally be avoided, and only reached for in the rare cases | ||
| where the ordinary control flow mechanisms will not suffice. | ||
| One such example is optimized state machines. |
Member
There was a problem hiding this comment.
This suggestion is perhaps excessively wordy, use what you like from it:
Suggested change
| One such example is optimized state machines. | |
| An example application where it is cleanest to reach for `@goto` is translating an arbitrary finite state machine (FSM) into Julia code. Even so, some classes of FSM have a natural representation in structured control-flow, see the following paper for an example: [^codeFSM]. | |
| [^codeFSM]: | |
| Jones, D.W., 1988. How (not) to code a finite state machine. ACM SIGPlan Notices, 23(8), pp.19-22. |
NB: IMO it is not appropriate to use "optimized" here, so this suggestion removes the word. It is natural to reach for @goto when implementing a state machine, however this has less to do with performance, rather it leads to cleaner code.
Member
Author
There was a problem hiding this comment.
I disagree - the easiest way to write a FSM is to use an integer as state, and then have a main loop with a big if/ifelse/else chain matching the integer. In my opinion, this is less verbose and easier to follow than a goto-based state machine, but is less efficient.
nsajko
reviewed
Jan 25, 2026
Keno
reviewed
Jan 26, 2026
Member
Author
|
Test failures seem unrelated |
* Rephrase `break` docstring to mention named break breaks from a named block in general, and not a loop. * Add a compat note to both `break` and `continue` docstrings * In break docstring, also include simple non-labeled usage example * In break docstring, also include non-loop code block break * In break docstring, highlight the returned value of `break name value` * Minor rephrasing of the newly added Manual section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documentation was largely missing from #60481.
Also document
@goto, which was not in the manual.