tmp/tmpbpslqau8/{from.md → to.md}
RENAMED
|
@@ -1,37 +1,42 @@
|
|
| 1 |
### The `for` statement <a id="stmt.for">[[stmt.for]]</a>
|
| 2 |
|
| 3 |
The `for` statement
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
-
'for ('
|
| 7 |
```
|
| 8 |
|
| 9 |
is equivalent to
|
| 10 |
|
| 11 |
-
except that names declared in the *
|
| 12 |
declarative region as those declared in the *condition*, and except that
|
| 13 |
a `continue` in *statement* (not enclosed in another iteration
|
| 14 |
statement) will execute *expression* before re-evaluating *condition*.
|
| 15 |
-
Thus the first statement specifies initialization for the loop; the
|
| 16 |
-
condition ([[stmt.select]]) specifies a test, made before each
|
| 17 |
-
iteration, such that the loop is exited when the condition becomes
|
| 18 |
-
`false`; the expression often specifies incrementing that is done after
|
| 19 |
-
each iteration.
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
missing *condition* makes the implied `while` clause equivalent to
|
| 23 |
`while(true)`.
|
| 24 |
|
| 25 |
-
If the *
|
| 26 |
declared extends to the end of the `for` statement.
|
| 27 |
|
|
|
|
|
|
|
| 28 |
``` cpp
|
| 29 |
int i = 42;
|
| 30 |
int a[10];
|
| 31 |
|
| 32 |
for (int i = 0; i < 10; i++)
|
| 33 |
a[i] = i;
|
| 34 |
|
| 35 |
int j = i; // j = 42
|
| 36 |
```
|
| 37 |
|
|
|
|
|
|
|
|
|
| 1 |
### The `for` statement <a id="stmt.for">[[stmt.for]]</a>
|
| 2 |
|
| 3 |
The `for` statement
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
+
'for (' init-statement conditionₒₚₜ ';' expressionₒₚₜ ')' statement
|
| 7 |
```
|
| 8 |
|
| 9 |
is equivalent to
|
| 10 |
|
| 11 |
+
except that names declared in the *init-statement* are in the same
|
| 12 |
declarative region as those declared in the *condition*, and except that
|
| 13 |
a `continue` in *statement* (not enclosed in another iteration
|
| 14 |
statement) will execute *expression* before re-evaluating *condition*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
[*Note 1*: Thus the first statement specifies initialization for the
|
| 17 |
+
loop; the condition ([[stmt.select]]) specifies a test, sequenced
|
| 18 |
+
before each iteration, such that the loop is exited when the condition
|
| 19 |
+
becomes `false`; the expression often specifies incrementing that is
|
| 20 |
+
sequenced after each iteration. — *end note*]
|
| 21 |
+
|
| 22 |
+
Either or both of the *condition* and the *expression* can be omitted. A
|
| 23 |
missing *condition* makes the implied `while` clause equivalent to
|
| 24 |
`while(true)`.
|
| 25 |
|
| 26 |
+
If the *init-statement* is a declaration, the scope of the name(s)
|
| 27 |
declared extends to the end of the `for` statement.
|
| 28 |
|
| 29 |
+
[*Example 1*:
|
| 30 |
+
|
| 31 |
``` cpp
|
| 32 |
int i = 42;
|
| 33 |
int a[10];
|
| 34 |
|
| 35 |
for (int i = 0; i < 10; i++)
|
| 36 |
a[i] = i;
|
| 37 |
|
| 38 |
int j = i; // j = 42
|
| 39 |
```
|
| 40 |
|
| 41 |
+
— *end example*]
|
| 42 |
+
|