I'm trying to declare and initialize variables of different type inside a for-scope. Something like:
for (int i = 0, double u = 1; i < 10; ++i)
{...}
but the compiler (gcc) returns me an error.
I know that can perform initialization using the same type variables (example), but I don't know how is it possible do it with different ones.
Of course I can declare the variable outside the loop:
double u = 1;
for (int i = 0; i < 10; ++i)
{...}
but I'm looking for something clean because the variable u
is used only inside the for-scope.
So,
- Can I do it?
- If so, how can I?