At i = 0, val is val + val + 1 = 0 + 0 + 1 = 1
at i = 1 valu is val + val + 1 = 1 + 1 + 1 = 3
at i = 2 val is val + val + 1 = 3 + 3 + 1 = 7.
Anyways if you compile with a cout you can see the results:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
int main()
{
int val = 0;
constint Iterations = 10;
for( int i = 0; i < Iterations; ++i )
{
val += val + 1;
std::cout << "Val = " << val << std::endl;
}
return 0;
}
Val = 1
Val = 3
Val = 7
Val = 15
Val = 31
Val = 63
Val = 127
Val = 255
Val = 511
Val = 1023