Can I create a for loop containing several types of declarations?

For instance:

Is there anything I can do that can allow me to do this:

for(TiXmlElement * pChild = elem->First(), int i=0; // note multiple type declarations pChild; pChild=pChild->NextSiblingElement(), i++) // note multiple types { //do stuff } 

Perhaps there is a boost header?

+4
source share
2 answers

Nope.

If you want to limit the amount of variables in the loop, just add another area:

 { TiXmlElement * pChild = elem->First(); int i = 0; for(; pChild; pChild=pChild->NextSiblingElement(), i++) { //do stuff } } 
+8
source

Blocks should not be tied to functions or conventions. You can surround any piece of code with a block to limit the scope of temporary variables to this block.

 { TiXmlElement * pChild; int i; for ( pChild = elem->First(), i = 0; pChild; pChild = pChild->NextSiblingElement(), ++i ) { // do stuff } } 
+5
source

Source: https://habr.com/ru/post/1340958/


All Articles