Re: Error: 'for' loop initial declaration used outside c99 mode



Pedro Pinto wrote:
When compiling my program i got this error:

Error: 'for' loop initial declaration used outside c99 mode


What is it and how can i solve it?

You're coming to C from a Java background, aren't you?

This is illegal in most C dialects; it is a legal C++ declaration, and
so may be accepted if you are compiling C with a C++ compiler:

for( int k=0; k<10; k++){}

I do like that syntax since it's such a common idiom to have a loop
iterator only in the scope of the loop.

.



Relevant Pages

  • Re: "Sorting" assignment
    ...     If clause-1 is a declaration, the scope of any variables it declares ... in that direction lies COBOL. ... >I don't declare anything inside of a loop is why. ...
    (comp.programming)
  • Re: About String
    ... Ada, where declarations are just as executable as statements. ... I think it does make sense because it clearly defines the scope ... anywhere outside the declaration part. ... for I in A'Range loop ...
    (comp.lang.ada)
  • Re: Error: for loop initial declaration used outside c99 mode
    ... 'for' loop initial declaration used outside c99 mode ... so may be accepted if you are compiling C with a C++ compiler: ... C99 mode, and use that mode. ...
    (comp.lang.c)
  • Re: Error: for loop initial declaration used outside c99 mode
    ... 'for' loop initial declaration used outside c99 mode ... You're coming to C from a Java background, ... so may be accepted if you are compiling C with a C++ compiler: ... I do like that syntax since it's such a common idiom to have a loop ...
    (comp.lang.c)
  • Re: Newbies question
    ... for I in Elements'Range loop ... I ruled out the declaration of a local array within the block statement Copy_List, because I thought that the compiler would mandate a return statement to be at the top level of the function's body, which I wouldn't be able to do, since the declared array would be local to the block statement. ...
    (comp.lang.ada)