You just have to understand the first statement is a declaration (and that comma is not the comma operator). It's not any harder to do:
for (int i, double d; ...)
Than it is:
int i, double d;
Because for (init cond; expr) statement
gets expanded to:
{
init
while (cond)
{
statement
expr;
}
}
A trick is to make that init
statement a struct definition and instance, like:
for (struct { int myIndex; MyElement* ptr;} data = {0, Pool->First};
data.ptr;
++data.myIndex, data.ptr = data.ptr->next)
{
// blah...
}
Which becomes the same as:
{
struct
{
int myIndex;
MyElement* ptr;
} data = {0, Pool->First};
while (data.ptr)
{
{
// blah...
}
++data.myIndex, data.ptr = data.ptr->next;
}
}
But I find that pretty ugly. In practice, I'd just split it up like you have. If scope is really a problem, which it probably isn't, throw the extra braces around there.
I don't think there's much to improve here without a bit of boilerplate code.