Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Multiple statements in for loop
Multiple statements in for loop [message #18436] |
Tue, 30 September 2008 20:31  |
|
Hi everybody!
I've just came to interesting problem while playing with a for loop controlled by two variables. Can somebody please tell me what's wrong with this code:for(bool first=true,bool cond=true;
first==true||cond==true;
cond=!(a>=3),first=false)
{
a++;
} It won't compile (using g++4.1) complaining about "error: expected unqualified-id before ‘bool’" in the first line.
When I declare the second bool before the loop like this:bool cond;
for(bool first=true,cond=true;
first==true||cond==true;
cond=!(a>=3),first=false)
{
a++;
} it compiles without errors...
So, my question is: Is this how the compiler is supposed to work? From what I've read, it should be allowed to use multiple declaration and/or expression statements (to cite concrete reference: http://msdn.microsoft.com/en-us/library/b80153d8.aspx). I'd like to know how to write it correctly, while keeping both variables defined only in the for loop scope (I mean any other way than enclosing it all into another set of {} braces ).
Bye, Honza
|
|
|
Goto Forum:
Current Time: Tue Apr 29 22:24:09 CEST 2025
Total time taken to generate the page: 0.00477 seconds
|