For example:
Is there anything I can do, that might 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?
Nope.
If you want to limit the scope of variables to the loop just add another scope:
{
TiXmlElement * pChild = elem->First();
int i = 0;
for(; pChild; pChild=pChild->NextSiblingElement(), i++)
{
//do stuff
}
}
Blocks do not have to be attached to functions or conditionals. You can surround any piece of code with a block to limit the scope of temporary variables to that block.
{
TiXmlElement * pChild;
int i;
for ( pChild = elem->First(), i = 0;
pChild;
pChild = pChild->NextSiblingElement(), ++i )
{
// do stuff
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With