0

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.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

0

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

why would it be bad style?

0

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

Edited by firstPerson: n/a

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.