For loop increment condition?

Hi everyone,

I just stumbled upon the solution to this exercise here:
http://en.wikibooks.org/wiki/C%2B%2B_Programming/Exercises/Iterations#EXERCISE_2

1
2
3
4
5
6
7
8
9
10
11
12
13
//Solution
#include <iostream>
using namespace std;
 
int main() {
    // Input and loop defined, only adds if input is correct.
    for (short int i = 8, input; i <= 23; i += (i == input)) {
        cout << "Enter the number " << i << ": ";
        cin >> input;
    }
 
    return 0;
}


Since this was the first time I've seen this, can someone explain to me why the for loop increment accepts a condition?

Also, I thought that += was the addition assignment operator? In this case I can see that i increments only when i == input, but if:

a = a+b
a += b

are both the same thing, how can i += (i == input) be the equivalent of doing ++i in this case?

Thanks for the help!
The boolean expression is promoted to type int. So if i == input is true then the expression is equal to 1 and equivalent to

i += 1;
Thank you.

I really couldn't wrap my head around this one, now it makes perfect sense.
Topic archived. No new replies allowed.