Hello all
I don't usually write posts here, as I can find most information in the books I have, but I really have an interesting question here.
I read some info on sequence points and order of evaluation in C++, but I'm still not sure about this issue.
I have the following code (tiny part of a bigger function ofcourse).
line is a string, ll is an int, j is an int and splitchar is a char
The object of this piece of code is to increase j by 1, as long as the characer of line with index j, equals splitchar.
The character of line with index j, before execution of the inner while loop code, always equals splitchar, quaranteed. So j will be increased by at least one.
//some code
int ll = line.length();
int j(0);
while(j < ll)
{
//some code that uses and changes j, but nothing very important. It doesn't influence the following code or the subject of this topic.
while (j < ll - 1 && line[j] == splitchar)
++j;
//some code
}
I changed the inner while loop to
while (j++ < ll - 1 && line[j] == splitchar)
continue;
or
while (j < ll - 1 && line[++j] == splitchar)
continue;
which are pretty much the same. Trust me, I've tested everything in detail ;)
Note: postfix or prefix notation is very important here!
Now, my questions are;
1. Does it matter if I write "continue", or empty braces ("{}") in the last two examples, and how does this affect the performance?
2. Which one of these three would have the best performance?
3. Is there an even better possibility?
Performance is not very important in this program, but I really want to know the little details, because it WILL matter in future projects.
Thanks in advance
Nick