Gábor Buella
Gábor Buella

Reputation: 1920

Is there a way to create a for loop with only two expressions in C?

I came across this in the C standard text, any version I can find for C99 or C11, at §6.8.5 :

iteration-statement:
  while ( expression ) statement
  do statement while ( expression ) ;
  for ( expression ; expression ; expression ) statement
  for ( declaration expression ;  expression ) statement

The fourth item here seems to be a for with only one semicolon, and I don't see any reference to this syntax anywhere else. Can anyone here explain what am I missing?

Upvotes: 18

Views: 1194

Answers (1)

nwellnhof
nwellnhof

Reputation: 33618

The production for declaration is:

declaration:
    declaration-specifiers init-declarator-listopt ;

So the semicolon is already part of it.

Upvotes: 25

Related Questions