Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Multiple statements in for loop
Re: Multiple statements in for loop [message #18438 is a reply to message #18436] Tue, 30 September 2008 20:45 Go to previous messageGo to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
As long as the two variables have same type, the:
bool a = true, b = true;

looks ok to me, the same declaration as outside of for can be used.
(and both are scoped as local variables)

The interesting question is what happens when you have:
bool b = false;  //outer scope
for ( bool a, b; ...

Is "b" still new variable?
I was so curious, that I had to try.
Yes, the second "b" is new local variable scoped to "for" only.
(both MSC8 and MINGW)

If you want two different types... how to?? I have no idea, looks impossible to me, to define them inside the "for".

Anyway allocating 2+ variables in for-init can often lead to less readable source, so use with caution. I think it's better to avoid it whenever possible.

Edit: I completely missed the "bool cond;" line from original post, so I was sort of thinking you already have correct solution for this case. Sorry, keep my mistake in mind when reading my reply, otherwise it may not make any sense. Wink

[Updated on: Tue, 30 September 2008 20:47]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: explanation of c++ typedef line
Next Topic: I don't get some aspects of STL ... [pointless rant]
Goto Forum:
  


Current Time: Mon May 13 04:42:09 CEST 2024

Total time taken to generate the page: 0.02200 seconds