@@ -1951,32 +1951,48 @@ while i < 10 {
1951
1951
1952
1952
### Infinite loops
1953
1953
1954
- A ` loop ` expression denotes an infinite loop:
1954
+ The keyword ` loop ` in Rust appears both in _ loop expressions_ and in _ continue expressions_ .
1955
+ A loop expression denotes an infinite loop;
1956
+ see [ Continue expressions] ( #continue-expressions ) for continue expressions.
1955
1957
1956
1958
~~~~~~~~ {.ebnf .gram}
1957
- loop_expr : "loop" '{' block '}';
1959
+ loop_expr : "loop" [ ident ':' ] '{' block '}';
1958
1960
~~~~~~~~
1959
1961
1962
+ A ` loop ` expression may optionally have a _ label_ .
1963
+ If a label is present,
1964
+ then labeled ` break ` and ` loop ` expressions nested within this loop may exit out of this loop or return control to its head.
1965
+ See [ Break expressions] ( #break-expressions ) .
1966
+
1960
1967
### Break expressions
1961
1968
1962
1969
~~~~~~~~ {.ebnf .gram}
1963
- break_expr : "break" ;
1970
+ break_expr : "break" [ ident ] ;
1964
1971
~~~~~~~~
1965
1972
1966
- Executing a ` break ` expression immediately terminates the innermost loop
1967
- enclosing it. It is only permitted in the body of a loop.
1973
+ A ` break ` expression has an optional ` label ` .
1974
+ If the label is absent, then executing a ` break ` expression immediately terminates the innermost loop enclosing it.
1975
+ It is only permitted in the body of a loop.
1976
+ If the label is present, then ` break foo ` terminates the loop with label ` foo ` ,
1977
+ which need not be the innermost label enclosing the ` break ` expression,
1978
+ but must enclose it.
1968
1979
1969
- ### Loop expressions
1980
+ ### Continue expressions
1970
1981
1971
1982
~~~~~~~~ {.ebnf .gram}
1972
- loop_expr : "loop" ;
1973
- ~~~~~~~~
1974
-
1975
- Evaluating a ` loop ` expression immediately terminates the current iteration of
1976
- the innermost loop enclosing it, returning control to the loop * head* . In the
1977
- case of a ` while ` loop, the head is the conditional expression controlling the
1978
- loop. In the case of a ` for ` loop, the head is the call-expression controlling
1979
- the loop.
1983
+ continue_expr : "loop" [ ident ];
1984
+ ~~~~~~~~
1985
+
1986
+ A continue expression, written ` loop ` , also has an optional ` label ` .
1987
+ If the label is absent,
1988
+ then executing a ` loop ` expression immediately terminates the current iteration of the innermost loop enclosing it,
1989
+ returning control to the loop * head* .
1990
+ In the case of a ` while ` loop,
1991
+ the head is the conditional expression controlling the loop.
1992
+ In the case of a ` for ` loop, the head is the call-expression controlling the loop.
1993
+ If the label is present, then ` loop foo ` returns control to the head of the loop with label ` foo ` ,
1994
+ which need not be the innermost label enclosing the ` break ` expression,
1995
+ but must enclose it.
1980
1996
1981
1997
A ` loop ` expression is only permitted in the body of a loop.
1982
1998
0 commit comments