| Marcan (24) | |||
|
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
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! | |||
|
|
|||
| vlad from moscow (3662) | |
|
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; | |
|
|
|
| Marcan (24) | |
|
Thank you. I really couldn't wrap my head around this one, now it makes perfect sense. | |
|
|
|