This is a very basic question but haven't been able to find a clear explanation. Why does the below code give 30 as a result for k?
I just would like to understand the mechanism, but for some reason, I cannot get my head around this. I know we first start looking at the inner for loop - we get 10 iterations until number2 reaches 10 (and k becomes 10, number 1 becomes 24. But what's next?
int number1(4), number2, k = 0;
while (number1 < 10)
{
for (number2 = 1; number2 <= 10; number2++)
++k;
number1 = number1 + 2;
}
cout << k << endl;