B
Brian
It's a minor thing, but I'm confused on the increment operator in a for loop.
I think most usually write:
for (int i = 0; i < something; i++)
{
....
}
But, in my book (from MSPress) it shows:
for (int i; i < something; ++i)
{
....
}
From what I remember in my readings, the ++i is supposed to be faster, performance
wise.
As far as results, they both seem to do the same thing in a loop.
In my tests, of "for (int i = 0, i < 9, ++i OR i++)", both loops iterated
from 0 to 9.
But, in reading up on the increment operator on MSDN:
++i = The result of the operation is the value of the operand after it has
been incremented.
i++ = The result of the operation is the value of the operand before it has
been incremented.
This doesn't seem to make sense. If ++i returns the value after it has been
incremented, then if i was initilized to 0, should the first loop in the
for loop have i = 1????
--Brian
I think most usually write:
for (int i = 0; i < something; i++)
{
....
}
But, in my book (from MSPress) it shows:
for (int i; i < something; ++i)
{
....
}
From what I remember in my readings, the ++i is supposed to be faster, performance
wise.
As far as results, they both seem to do the same thing in a loop.
In my tests, of "for (int i = 0, i < 9, ++i OR i++)", both loops iterated
from 0 to 9.
But, in reading up on the increment operator on MSDN:
++i = The result of the operation is the value of the operand after it has
been incremented.
i++ = The result of the operation is the value of the operand before it has
been incremented.
This doesn't seem to make sense. If ++i returns the value after it has been
incremented, then if i was initilized to 0, should the first loop in the
for loop have i = 1????
--Brian