If you look closely at this program, you'll notice that the
for loop and the
while loop are quite similar to each other. They're both incrementing a value, and they both depend on a pre-existing, nonzero value to repeat for...
- Try tracing your variables (n, a, and result) throughout the program.
- Pay attention to how one variable changes in relation to another.
- Moreover, try to discern what each loop is doing to its variables. What stands out to you?