Re: For loop Multiple Initialization
On Nov 3, 10:29 pm, "charlie.xia....@gmail.com" <lxia....@gmail.com>
wrote:
for(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--) {}
example from:http://www.tech-faq.com/iterations.shtml
Is not valid in my eclipse cdt.
It's not valid in C++ either. Just another case of someone who
doesn't know the language trying to write about it.
Is there multiple initialization in C++?
Sort of. You can only write one declaration statement, but it
can define multiple variables, e.g.:
for ( int i = 0, j = 10 ; ... )
Generally speaking, i'ld avoid it, because it is confusing to
have multiple variables defined in the same declaration. But
there are probably exceptions; I know that some people like:
for ( Container::const_iterator
current = c.begin(), end = c.end() ;
current != end ;
++ current )
I'm not that fond of it, but if you raise it to the level of a
"standard idiom" in your code, I don't think I'd have any real
objections.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34