Which would be considering a better coding style, this is for a merge sort in case you are wondering what I am doing with this line of code

int j = 0; // used to track for the temp array earlier in my code
              // reset it to be reused as opposed to creating another int
for (int k = first; k < last; k++)
{
     data[k] = merged[j];
     j++;
}

//versus......

for (int k = first, int m = 0; k < last; k++, m++)
{
     data[k] = merged[m];
     m++;
}

just curious if it is bad coding style to have multiple declarations in my for loop.

I like the second example better, but delete line 14. Of course it won't work if you need to know the value of m after the loop terminates.

just curious if it is bad coding style to have multiple declarations in my for loop.

why would it be bad style?

I like the second one, if it would compile :) And why are u incrementing m two times per a loop.

Edited 6 Years Ago by firstPerson: n/a

I like the second one, if it would compile :).

You're right -- should have been this: for (int k = first, m = 0; k < last; k++, m++)

This question has already been answered. Start a new discussion instead.