Skip to content

Commit f8dfbdc

Browse files
committed
Add documentation for loop_break_value
This commit introduces to the reference the changes made by the loop_break_value feature, defined in RFC 1624.
1 parent 8d7e097 commit f8dfbdc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/expressions.md

+13
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,11 @@ within this loop may exit out of this loop or return control to its head.
600600
See [break expressions](#break-expressions) and [continue
601601
expressions](#continue-expressions).
602602

603+
A `loop` expression is [diverging](items.html#diverging-functions), and doesn't
604+
return anything. However, when it contains a [break
605+
expression](#break-expressions), it returns the value attached to the `break`
606+
that caused the loop to stop.
607+
603608
## `break` expressions
604609

605610
A `break` expression has an optional _label_. If the label is absent, then
@@ -608,6 +613,14 @@ enclosing it. It is only permitted in the body of a loop. If the label is
608613
present, then `break 'foo` terminates the loop with label `'foo`, which need not
609614
be the innermost label enclosing the `break` expression, but must enclose it.
610615

616+
When the `break` expression is enclosed in a `loop` it has an optional return
617+
value attached which will be returned by the loop ended by the
618+
expression. When it's not provided it defaults to `()`.
619+
620+
If both a label and a return value are present in the expression, the label
621+
must be placed before the return value. For example `break 'label 42` breaks
622+
the loop labelled `'label`, returning `42` from it.
623+
611624
## `continue` expressions
612625

613626
A `continue` expression has an optional _label_. If the label is absent, then

0 commit comments

Comments
 (0)