6.8.5 Iteration statements
Syntax
1 iteration-statement:
while ( expression ) statement
do statement while ( expression ) ;
for ( expression[opt] ; expression[opt] ;
expression[opt] ) statement
for ( declaration expression[opt] ; expression
[opt] ) statement
There is no semicolon in the last iteration-statement option.
The following text assumes there's a semicolon and uses "clause-1"
instead of "expression-1" or "declaration"
Maybe the syntax for both "for" statements could be made only one?
for ( clause ; expression[opt] ; expression
[opt] ) statement
(Reformatted to fit this screen.)
That's correct.
No semicolon is needed after "declaration" because a declaration
includes a semicolon. For example, in:
for (int i = 0; i < 10; i ++) ...
"int i = 0;" is the declaration.
(There's also no semicolon needed after "statement"; the statement
part either provides its own semicolon or, if it's a compound
statement, doesn't need one.)
> The following text assumes there's a semicolon and uses "clause-1"
> instead of "expression-1" or "declaration"
>
>
> Maybe the syntax for both "for" statements could be made only one?
>
> for ( clause ; expression[opt] ; expression[opt] ) statement
The syntax for "clause" would have to match either an optional
expression or a declaration with the final semicolon removed.
The following wording:
The statement
for ( clause-1 ; expression-2 ; expression-3 ) statement
behaves as follows:
...
If clause-1 is a declaration
...
is slightly sloppy. Strictly speaking, clause-1 cannot be a
declaration; it's a declaration minus the semicolon.
One way to fix this, I suppose, would be to alter the definition
of "declaration" so it *doesn't* include the trailing semicolon,
and replace occurrences of "declaration" with "declaration ;",
but I don't think that would be worth the effort.
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
> I've checked the three PDFs n1256.pdf (page 147), n1336.pdf (page
> 149), and n1362.pdf (page 151) and found the same omission on all of
> them
>
> 6.8.5 Iteration statements
> Syntax
>
> 1 iteration-statement:
> while ( expression ) statement
> do statement while ( expression ) ;
> for ( expression[opt] ; expression[opt] ;
> expression[opt] ) statement
> for ( declaration expression[opt] ; expression
> [opt] ) statement
>
> There is no semicolon in the last iteration-statement option.
>
The description in the syntax section must be exact to the letter, and
therefor it omits the semicolon because it already and always appears as
part of the declaration. In the description of for, it uses "clause-1" to
catch both for-cases into one. In my opinion, that goes alright.
Silly me :o
Thank you for the quick and comprehensive answer!
Sorry for the disturbance
That's because the grammar for "declaration" includes the semicolon.
--
Larry Jones
I've got more brains than I know what to do with. -- Calvin