Line: | Loopy Line | Type: | Exercise |
You should have completed: | Counting Up Again | This topic leads to: | Debugger |
This exercise revisits an earlier example of data processing (in this case adding up) and makes the code more efficient by using iteration structures.
Using a while loop executes until some condition becomes true, rather than a set number of times. It is the ideal solution when we cannot know or calculate how many times to repeat a task, for example where the user is selecting whether to continue or not. Do...while loops are useful in similar circumstances with the exception that they always run at least once.