开发者

for loop is giving different result than +=

开发者 https://www.devze.com 2023-02-19 18:45 出处:网络
I really do not understand what开发者_运维问答 is happening here but: when I do: colorIndex += len - stopPos;

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

精彩评论

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

关注公众号