Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"for" in clause 6.8.5 of the Standard

0 views
Skip to first unread message

Mara Guida

unread,
Oct 21, 2009, 3:55:47 PM10/21/09
to
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 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

Keith Thompson

unread,
Oct 21, 2009, 4:17:57 PM10/21/09
to
Mara Guida <mara...@gmail.com> writes:
> 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.

(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"

Johannes Schaub (litb)

unread,
Oct 21, 2009, 4:23:46 PM10/21/09
to
Mara Guida wrote:

> 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.

Mara Guida

unread,
Oct 21, 2009, 4:29:20 PM10/21/09
to
Keith Thompson wrote:
> Mara Guida <mara...@gmail.com> writes:
> > ...
> > 6.8.5 Iteration statements
> > ...

> > for ( declaration
> > expression[opt] ;
> > expression[opt] ) statement
> >
> > There is no semicolon in the last iteration-statement option.
>
> That's correct.
>
> No semicolon is needed after "declaration" because a declaration
> includes a semicolon.
> ...

Silly me :o
Thank you for the quick and comprehensive answer!

Sorry for the disturbance

lawrenc...@siemens.com

unread,
Oct 21, 2009, 5:58:43 PM10/21/09
to
Mara Guida <mara...@gmail.com> wrote:
> 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.

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

0 new messages