开发者

for loop is giving different result than +=

I really do not understand what开发者_运维问答 is happening here but:

when I do:

colorIndex += len - stopPos;
for(int m = 0; m < len - stopPos; m++)
{
    colorUniPos++;
}

it does not give me the same result as doing:

colorIndex += len - stopPos;
colorUniPos += len - stopPos;

I think it becomes off by one or something. Shouldn't both of these obtain the same result?

Thanks


This won't produce the same result if len - stopPos < 0


This is correct if len - stopPos is a positive value or zero, but for negative values colorUniPos just keeps its value because the loop isn't executed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜