1 2 3 4 5
|
const int ArSize = 4;
for ( int i = 2; i < ArSize; i++ )
{
// body
}
|
* The i is initially 2.
* On first try the condition (2<4) is true, the loop body is executed, and i is incremented to 3.
* On second try the condition (3<4) is still true, the loop body is executed, and i is incremented to 4.
* On third try the condition (4<4) is false, the loop is over. Execution continues from your line 9.
1 2 3
|
const int ArSize = 4;
long long factorials[ArSize];
factorials[1] = factorials[0] = 1LL;
|
Initially:
factorials[0] == 1
factorials[1] == 1
factorials[2] is undefined
factorials[3] is undefined
The first execution of the loop's body evaluates this:
factorials[2] = 2 * factorials[1];
That updates factorials[2] to 2
The second execution of the loop's body evaluates this:
factorials[3] = 3 * factorials[2];
That updates factorials[3] to 6