Step-by-Step Execution
| Loop Step | i Value | Expression (i + value) | New value Calculation | Updated value |
|---|---|---|---|---|
| Start | — | — | — | 2 |
| 1st loop | 1 | 1 + 2 = 3 | 2 + 3 | 5 |
| 2nd loop | 2 | 2 + 5 = 7 | 5 + 7 | 12 |
| 3rd loop | 3 | 3 + 12 = 15 | 12 + 15 | 27 |
✅ Final Output
27Why this happens?
Each loop uses the updated value to calculate the next addition.
So the value grows faster (this is an example of cumulative feedback in loops).


0 Comments:
Post a Comment