简体   繁体   中英

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

如果len-stopPos <0,则不会产生相同的结果

如果len - stopPos是正值或零,这是正确的,但对于负值, colorUniPos只是保留其值,因为未执行循环。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM