Skip to content

Conversation

@jakobnissen
Copy link
Member

Documentation was largely missing from #60481.

Also document @goto, which was not in the manual.

@nsajko nsajko added the docs This change adds or pertains to documentation label 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

* 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
@jakobnissen
Copy link
Member Author

Test failures seem unrelated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs This change adds or pertains to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants