@@ -3078,28 +3078,6 @@ fn ten_times<F>(f: F) where F: Fn(i32) {
3078
3078
ten_times(|j| println!("hello, {}", j));
3079
3079
```
3080
3080
3081
- ### While loops
3082
-
3083
- ``` {.ebnf .gram}
3084
- while_expr : [ lifetime ':' ] "while" no_struct_literal_expr '{' block '}' ;
3085
- ```
3086
-
3087
- A ` while ` loop begins by evaluating the boolean loop conditional expression.
3088
- If the loop conditional expression evaluates to ` true ` , the loop body block
3089
- executes and control returns to the loop conditional expression. If the loop
3090
- conditional expression evaluates to ` false ` , the ` while ` expression completes.
3091
-
3092
- An example:
3093
-
3094
- ```
3095
- let mut i = 0;
3096
-
3097
- while i < 10 {
3098
- println!("hello");
3099
- i = i + 1;
3100
- }
3101
- ```
3102
-
3103
3081
### Infinite loops
3104
3082
3105
3083
A ` loop ` expression denotes an infinite loop.
@@ -3108,10 +3086,11 @@ A `loop` expression denotes an infinite loop.
3108
3086
loop_expr : [ lifetime ':' ] "loop" '{' block '}';
3109
3087
```
3110
3088
3111
- A ` loop ` expression may optionally have a _ label_ . If a label is present, then
3112
- labeled ` break ` and ` continue ` expressions nested within this loop may exit out
3113
- of this loop or return control to its head. See [ Break
3114
- expressions] ( #break-expressions ) and [ Continue
3089
+ A ` loop ` expression may optionally have a _ label_ . The label is written as
3090
+ a lifetime preceding the loop expression, as in ` 'foo: loop{ } ` . If a
3091
+ label is present, then labeled ` break ` and ` continue ` expressions nested
3092
+ within this loop may exit out of this loop or return control to its head.
3093
+ See [ Break expressions] ( #break-expressions ) and [ Continue
3115
3094
expressions] ( #continue-expressions ) .
3116
3095
3117
3096
### Break expressions
@@ -3123,7 +3102,7 @@ break_expr : "break" [ lifetime ];
3123
3102
A ` break ` expression has an optional _ label_ . If the label is absent, then
3124
3103
executing a ` break ` expression immediately terminates the innermost loop
3125
3104
enclosing it. It is only permitted in the body of a loop. If the label is
3126
- present, then ` break foo ` terminates the loop with label ` foo ` , which need not
3105
+ present, then ` break ' foo ` terminates the loop with label ` ' foo` , which need not
3127
3106
be the innermost label enclosing the ` break ` expression, but must enclose it.
3128
3107
3129
3108
### Continue expressions
@@ -3137,12 +3116,39 @@ executing a `continue` expression immediately terminates the current iteration
3137
3116
of the innermost loop enclosing it, returning control to the loop * head* . In
3138
3117
the case of a ` while ` loop, the head is the conditional expression controlling
3139
3118
the loop. In the case of a ` for ` loop, the head is the call-expression
3140
- controlling the loop. If the label is present, then ` continue foo ` returns
3141
- control to the head of the loop with label ` foo ` , which need not be the
3119
+ controlling the loop. If the label is present, then ` continue ' foo ` returns
3120
+ control to the head of the loop with label ` ' foo` , which need not be the
3142
3121
innermost label enclosing the ` break ` expression, but must enclose it.
3143
3122
3144
3123
A ` continue ` expression is only permitted in the body of a loop.
3145
3124
3125
+ ### While loops
3126
+
3127
+ ``` {.ebnf .gram}
3128
+ while_expr : [ lifetime ':' ] "while" no_struct_literal_expr '{' block '}' ;
3129
+ ```
3130
+
3131
+ A ` while ` loop begins by evaluating the boolean loop conditional expression.
3132
+ If the loop conditional expression evaluates to ` true ` , the loop body block
3133
+ executes and control returns to the loop conditional expression. If the loop
3134
+ conditional expression evaluates to ` false ` , the ` while ` expression completes.
3135
+
3136
+ An example:
3137
+
3138
+ ```
3139
+ let mut i = 0;
3140
+
3141
+ while i < 10 {
3142
+ println!("hello");
3143
+ i = i + 1;
3144
+ }
3145
+ ```
3146
+
3147
+ Like ` loop ` expressions, ` while ` loops can be controlled with ` break ` or
3148
+ ` continue ` , and may optionally have a _ label_ . See [ infinite
3149
+ loops] ( #infinite-loops ) , [ break expressions] ( #break-expressions ) , and
3150
+ [ continue expressions] ( #continue-expressions ) for more information.
3151
+
3146
3152
### For expressions
3147
3153
3148
3154
``` {.ebnf .gram}
@@ -3177,6 +3183,11 @@ for i in 0..256 {
3177
3183
}
3178
3184
```
3179
3185
3186
+ Like ` loop ` expressions, ` while ` loops can be controlled with ` break ` or
3187
+ ` continue ` , and may optionally have a _ label_ . See [ infinite
3188
+ loops] ( #infinite-loops ) , [ break expressions] ( #break-expressions ) , and
3189
+ [ continue expressions] ( #continue-expressions ) for more information.
3190
+
3180
3191
### If expressions
3181
3192
3182
3193
``` {.ebnf .gram}
0 commit comments