C ++: order of operations for part of the increment of a loop

Consider the following code snippet:

int totalLength = 0;
int partLength = 0;
for(; totalLength < SOME_CONST; totalLength += partLength, partLength = 0)
{
    //partLength may be increased here
}

In this particular case, can I assume that partLength will be set to 0 AFTER it is added to totalLength (so if partLength is increased in the body of the loop, I will not add 0 to totalLength at the end of the loop)? I read about C ++ sequences, etc., but did not find a clear answer.

+4
source share
1 answer

Yes. The left side of the statement comma is sequenced in front of the right side. totalLength += partLengthwill be fully appreciated before implementation partLength = 0.

+5
source

All Articles