[Solved] How is the second for loop output 4. Shouldn’t it be 3?


It’s because your product starts at 1. If it started at zero, the product would be three. Assuming that only the second loop is running.

If the first loop is running as well, then I would expect the result to be 5. Since product = 2 after the first loop, then 0 + 1 + 2 is added from the second loop for a total of 5.

4

solved How is the second for loop output 4. Shouldn’t it be 3?