Init
This commit is contained in:
49
cppdraft/stmt/for.md
Normal file
49
cppdraft/stmt/for.md
Normal file
@@ -0,0 +1,49 @@
|
||||
[stmt.for]
|
||||
|
||||
# 8 Statements [[stmt]](./#stmt)
|
||||
|
||||
## 8.6 Iteration statements [[stmt.iter]](stmt.iter#stmt.for)
|
||||
|
||||
### 8.6.4 The for statement [stmt.for]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L663)
|
||||
|
||||
The for statement
|
||||
|
||||
for ( [*init-statement*](stmt.pre#nt:init-statement "8.1 Preamble [stmt.pre]") [*condition*](stmt.pre#nt:condition "8.1 Preamble [stmt.pre]")opt ; [*expression*](expr.comma#nt:expression "7.6.20 Comma operator [expr.comma]")opt ) [*statement*](stmt.pre#nt:statement "8.1 Preamble [stmt.pre]")
|
||||
|
||||
is equivalent to
|
||||
|
||||
{
|
||||
[*init-statement*](stmt.pre#nt:init-statement "8.1 Preamble [stmt.pre]")
|
||||
while ( [*condition*](stmt.pre#nt:condition "8.1 Preamble [stmt.pre]") ) {
|
||||
[*statement*](stmt.pre#nt:statement "8.1 Preamble [stmt.pre]")
|
||||
[*expression*](expr.comma#nt:expression "7.6.20 Comma operator [expr.comma]") ;
|
||||
}
|
||||
}
|
||||
|
||||
except that the [*init-statement*](stmt.pre#nt:init-statement "8.1 Preamble [stmt.pre]") is
|
||||
in the same scope as the [*condition*](stmt.pre#nt:condition "8.1 Preamble [stmt.pre]"), and
|
||||
except that acontinue in [*statement*](stmt.pre#nt:statement "8.1 Preamble [stmt.pre]") (not enclosed in another
|
||||
iteration statement) will execute [*expression*](expr.comma#nt:expression "7.6.20 Comma operator [expr.comma]") before
|
||||
re-evaluating [*condition*](stmt.pre#nt:condition "8.1 Preamble [stmt.pre]")[.](#1.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Thus the first statement specifies initialization for the loop; the
|
||||
condition ([[stmt.pre]](stmt.pre "8.1 Preamble")) specifies a test, sequenced before each
|
||||
iteration, such that the loop is exited when the condition becomesfalse; the expression often specifies incrementing that is
|
||||
sequenced after each iteration[.](#1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L693)
|
||||
|
||||
Either or both of the [*condition*](stmt.pre#nt:condition "8.1 Preamble [stmt.pre]") and the [*expression*](expr.comma#nt:expression "7.6.20 Comma operator [expr.comma]") can be omitted[.](#2.sentence-1)
|
||||
|
||||
A missing [*condition*](stmt.pre#nt:condition "8.1 Preamble [stmt.pre]") makes the implied while clause
|
||||
equivalent to while (true)[.](#2.sentence-2)
|
||||
Reference in New Issue
Block a user