An if-statement implies a conditional branch which might be a bit more expensive that a code that doesn't branch.
As an example, counting how many times a condition is true (e.g how many numbers in a vector are greater than 10000):
for (std::vector<int>::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {
//if (*it > 10000) ++count;
count += *it > 10000;
}
The version which simply adds 1 or 0 to the running total may be a tiny amount faster (I tried with 100 million numbers before I could discern a difference).
However, with MinGW 3.4.5, using a dedicated standard algorithm turns out to be noticeably faster:
count = std::count_if(v.begin(), v.end(), std::bind2nd(std::greater<int>(), 10000));
So the lesson is that before starting to optimize prematurely, using some tricks you've learnt off the internets, you might try out recommended practices for the language. (And naturally make sure first, that that part of the program is unreasonably slow in the first place.)
Another place where you can often avoid evaluating complicated conditions is using look-up tables (a rule of thumb: algorithms can often be made faster if you let them use more memory). For example, counting vowels (aeiou) in a word-list, where you can avoid branching and evaluating multiple conditions:
unsigned char letters[256] = {0};
letters['a'] = letters['e'] = letters['i'] = letters['o'] = letters['u'] = 1;
for (std::vector<std::string>::const_iterator it = words.begin(), end = words.end(); it != end; ++it) {
for (std::string::const_iterator w_it = it->begin(), w_end = it->end(); w_it != w_end; ++w_it) {
unsigned char c = *w_it;
/*if (c == 'e' || c == 'a' || c == 'i' || c == 'o' || c == 'u') {
++count;
}*/
count += letters[c];
}
}