From Jason Turner

[stmt.iter]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpn27zll86/{from.md → to.md} +68 -50
tmp/tmpn27zll86/{from.md → to.md} RENAMED
@@ -2,14 +2,14 @@
2
 
3
  Iteration statements specify looping.
4
 
5
  ``` bnf
6
  iteration-statement:
7
- 'while (' condition ')' statement
8
- 'do' statement 'while (' expression ') ;'
9
- 'for (' init-statement conditionₒₚₜ ';' expressionₒₚₜ ')' statement
10
- 'for (' for-range-declaration ':' for-range-initializer ')' statement
11
  ```
12
 
13
  ``` bnf
14
  for-range-declaration:
15
  attribute-specifier-seqₒₚₜ decl-specifier-seq declarator
@@ -25,16 +25,14 @@ See  [[dcl.meaning]] for the optional *attribute-specifier-seq* in a
25
  *for-range-declaration*.
26
 
27
  [*Note 1*: An *init-statement* ends with a semicolon. — *end note*]
28
 
29
  The substatement in an *iteration-statement* implicitly defines a block
30
- scope ([[basic.scope]]) which is entered and exited each time through
31
- the loop.
32
-
33
- If the substatement in an iteration-statement is a single statement and
34
- not a *compound-statement*, it is as if it was rewritten to be a
35
- compound-statement containing the original statement.
36
 
37
  [*Example 1*:
38
 
39
  ``` cpp
40
  while (--x >= 0)
@@ -71,36 +69,31 @@ void f() {
71
  — *end example*]
72
 
73
  ### The `while` statement <a id="stmt.while">[[stmt.while]]</a>
74
 
75
  In the `while` statement the substatement is executed repeatedly until
76
- the value of the condition ([[stmt.select]]) becomes `false`. The test
77
  takes place before each execution of the substatement.
78
 
79
  When the condition of a `while` statement is a declaration, the scope of
80
- the variable that is declared extends from its point of declaration (
81
- [[basic.scope.pdecl]]) to the end of the `while` *statement*. A `while`
82
- statement of the form
83
 
84
- ``` cpp
85
- while (T t = x) statement
86
- ```
87
-
88
- is equivalent to
89
-
90
- ``` cpp
91
- label:
92
- { // start of condition scope
93
- T t = x;
94
- if (t) {
95
  statement
96
- goto label;
97
- }
98
- } // end of condition scope
99
  ```
100
 
101
- The variable created in a condition is destroyed and created with each
 
 
102
  iteration of the loop.
103
 
104
  [*Example 1*:
105
 
106
  ``` cpp
@@ -121,39 +114,51 @@ In the while-loop, the constructor and destructor are each called twice,
121
  once for the condition that succeeds and once for the condition that
122
  fails.
123
 
124
  — *end example*]
125
 
 
 
126
  ### The `do` statement <a id="stmt.do">[[stmt.do]]</a>
127
 
128
- The expression is contextually converted to `bool` (Clause  [[conv]]);
129
- if that conversion is ill-formed, the program is ill-formed.
130
 
131
  In the `do` statement the substatement is executed repeatedly until the
132
  value of the expression becomes `false`. The test takes place after each
133
  execution of the statement.
134
 
135
  ### The `for` statement <a id="stmt.for">[[stmt.for]]</a>
136
 
137
  The `for` statement
138
 
139
  ``` bnf
140
- 'for (' init-statement conditionₒₚₜ ';' expressionₒₚₜ ')' statement
141
  ```
142
 
143
  is equivalent to
144
 
 
 
 
 
 
 
 
 
 
 
145
  except that names declared in the *init-statement* are in the same
146
  declarative region as those declared in the *condition*, and except that
147
  a `continue` in *statement* (not enclosed in another iteration
148
  statement) will execute *expression* before re-evaluating *condition*.
149
 
150
  [*Note 1*: Thus the first statement specifies initialization for the
151
- loop; the condition ([[stmt.select]]) specifies a test, sequenced
152
- before each iteration, such that the loop is exited when the condition
153
- becomes `false`; the expression often specifies incrementing that is
154
- sequenced after each iteration. — *end note*]
155
 
156
  Either or both of the *condition* and the *expression* can be omitted. A
157
  missing *condition* makes the implied `while` clause equivalent to
158
  `while(true)`.
159
 
@@ -177,39 +182,52 @@ int j = i; // j = 42
177
  ### The range-based `for` statement <a id="stmt.ranged">[[stmt.ranged]]</a>
178
 
179
  The range-based `for` statement
180
 
181
  ``` bnf
182
- 'for (' for-range-declaration ':' for-range-initializer ')' statement
183
  ```
184
 
185
  is equivalent to
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  where
188
 
189
  - if the *for-range-initializer* is an *expression*, it is regarded as
190
  if it were surrounded by parentheses (so that a comma operator cannot
191
  be reinterpreted as delimiting two *init-declarator*s);
192
- - `__range`, `__begin`, and `__end` are variables defined for exposition
193
  only; and
194
  - *begin-expr* and *end-expr* are determined as follows:
195
  - if the *for-range-initializer* is an expression of array type `R`,
196
- *begin-expr* and *end-expr* are `__range` and `__range + __bound`,
197
- respectively, where `__bound` is the array bound. If `R` is an array
198
- of unknown bound or an array of incomplete type, the program is
199
  ill-formed;
200
  - if the *for-range-initializer* is an expression of class type `C`,
201
  the *unqualified-id*s `begin` and `end` are looked up in the scope
202
- of `C` as if by class member access lookup (
203
- [[basic.lookup.classref]]), and if either (or both) finds at least
204
- one declaration, *begin-expr* and *end-expr* are `__range.begin()`
205
- and `__range.end()`, respectively;
206
- - otherwise, *begin-expr* and *end-expr* are `begin(__range)` and
207
- `end(__range)`, respectively, where `begin` and `end` are looked up
208
- in the associated namespaces ([[basic.lookup.argdep]]).
209
- \[*Note 1*: Ordinary unqualified lookup ([[basic.lookup.unqual]])
210
- is not performed. — *end note*]
211
 
212
  [*Example 1*:
213
 
214
  ``` cpp
215
  int array[5] = { 1, 2, 3, 4, 5 };
 
2
 
3
  Iteration statements specify looping.
4
 
5
  ``` bnf
6
  iteration-statement:
7
+ while '(' condition ')' statement
8
+ do statement while '(' expression ')' ';'
9
+ for '(' init-statement conditionₒₚₜ ';' expressionₒₚₜ ')' statement
10
+ for '(' init-statementₒₚₜ for-range-declaration ':' for-range-initializer ')' statement
11
  ```
12
 
13
  ``` bnf
14
  for-range-declaration:
15
  attribute-specifier-seqₒₚₜ decl-specifier-seq declarator
 
25
  *for-range-declaration*.
26
 
27
  [*Note 1*: An *init-statement* ends with a semicolon. — *end note*]
28
 
29
  The substatement in an *iteration-statement* implicitly defines a block
30
+ scope [[basic.scope]] which is entered and exited each time through the
31
+ loop. If the substatement in an *iteration-statement* is a single
32
+ statement and not a *compound-statement*, it is as if it was rewritten
33
+ to be a *compound-statement* containing the original statement.
 
 
34
 
35
  [*Example 1*:
36
 
37
  ``` cpp
38
  while (--x >= 0)
 
69
  — *end example*]
70
 
71
  ### The `while` statement <a id="stmt.while">[[stmt.while]]</a>
72
 
73
  In the `while` statement the substatement is executed repeatedly until
74
+ the value of the condition [[stmt.select]] becomes `false`. The test
75
  takes place before each execution of the substatement.
76
 
77
  When the condition of a `while` statement is a declaration, the scope of
78
+ the variable that is declared extends from its point of declaration
79
+ [[basic.scope.pdecl]] to the end of the `while` *statement*. A `while`
80
+ statement is equivalent to
81
 
82
+ ``` bnf
83
+ label ':'
84
+ '{'
85
+ if '(' condition ')' '{'
 
 
 
 
 
 
 
86
  statement
87
+ goto label ';'
88
+ '}'
89
+ '}'
90
  ```
91
 
92
+ [*Note 1*:
93
+
94
+ The variable created in the condition is destroyed and created with each
95
  iteration of the loop.
96
 
97
  [*Example 1*:
98
 
99
  ``` cpp
 
114
  once for the condition that succeeds and once for the condition that
115
  fails.
116
 
117
  — *end example*]
118
 
119
+ — *end note*]
120
+
121
  ### The `do` statement <a id="stmt.do">[[stmt.do]]</a>
122
 
123
+ The expression is contextually converted to `bool` [[conv]]; if that
124
+ conversion is ill-formed, the program is ill-formed.
125
 
126
  In the `do` statement the substatement is executed repeatedly until the
127
  value of the expression becomes `false`. The test takes place after each
128
  execution of the statement.
129
 
130
  ### The `for` statement <a id="stmt.for">[[stmt.for]]</a>
131
 
132
  The `for` statement
133
 
134
  ``` bnf
135
+ for '(' init-statement conditionₒₚₜ ';' expressionₒₚₜ ')' statement
136
  ```
137
 
138
  is equivalent to
139
 
140
+ ``` bnf
141
+ '{'
142
+ init-statement
143
+ while '(' condition ')' '{'
144
+ statement
145
+ expression ';'
146
+ '}'
147
+ '}'
148
+ ```
149
+
150
  except that names declared in the *init-statement* are in the same
151
  declarative region as those declared in the *condition*, and except that
152
  a `continue` in *statement* (not enclosed in another iteration
153
  statement) will execute *expression* before re-evaluating *condition*.
154
 
155
  [*Note 1*: Thus the first statement specifies initialization for the
156
+ loop; the condition [[stmt.select]] specifies a test, sequenced before
157
+ each iteration, such that the loop is exited when the condition becomes
158
+ `false`; the expression often specifies incrementing that is sequenced
159
+ after each iteration. — *end note*]
160
 
161
  Either or both of the *condition* and the *expression* can be omitted. A
162
  missing *condition* makes the implied `while` clause equivalent to
163
  `while(true)`.
164
 
 
182
  ### The range-based `for` statement <a id="stmt.ranged">[[stmt.ranged]]</a>
183
 
184
  The range-based `for` statement
185
 
186
  ``` bnf
187
+ for '(' init-statementₒₚₜ for-range-declaration ':' for-range-initializer ')' statement
188
  ```
189
 
190
  is equivalent to
191
 
192
+ ``` bnf
193
+ '{'
194
+ init-statementₒₚₜ
195
+ auto '&&'range '=' for-range-initializer ';'
196
+ auto begin '=' begin-expr ';'
197
+ auto end '=' end-expr ';'
198
+ for '(' ';' begin '!=' end';' '++'begin ')' '{'
199
+ for-range-declaration '=' '*' begin ';'
200
+ statement
201
+ '}'
202
+ '}'
203
+ ```
204
+
205
  where
206
 
207
  - if the *for-range-initializer* is an *expression*, it is regarded as
208
  if it were surrounded by parentheses (so that a comma operator cannot
209
  be reinterpreted as delimiting two *init-declarator*s);
210
+ - *`range`*, *`begin`*, and *`end`* are variables defined for exposition
211
  only; and
212
  - *begin-expr* and *end-expr* are determined as follows:
213
  - if the *for-range-initializer* is an expression of array type `R`,
214
+ *begin-expr* and *end-expr* are *`range`* and *`range`* `+` `N`,
215
+ respectively, where `N` is the array bound. If `R` is an array of
216
+ unknown bound or an array of incomplete type, the program is
217
  ill-formed;
218
  - if the *for-range-initializer* is an expression of class type `C`,
219
  the *unqualified-id*s `begin` and `end` are looked up in the scope
220
+ of `C` as if by class member access lookup
221
+ [[basic.lookup.classref]], and if both find at least one
222
+ declaration, *begin-expr* and *end-expr* are `range.begin()` and
223
+ `range.end()`, respectively;
224
+ - otherwise, *begin-expr* and *end-expr* are `begin(range)` and
225
+ `end(range)`, respectively, where `begin` and `end` are looked up in
226
+ the associated namespaces [[basic.lookup.argdep]].
227
+ \[*Note 1*: Ordinary unqualified lookup [[basic.lookup.unqual]] is
228
+ not performed. — *end note*]
229
 
230
  [*Example 1*:
231
 
232
  ``` cpp
233
  int array[5] = { 1, 2, 3, 4, 5 };