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