Infinite Loop
Infinite looping occurs when we aren't making progress towards loop termination. There are several situation when we will end up with an infinite loop. The example below illustrates the problem where we are trying to display the sum of all numbers from 5 to 10.
We will end up with an infinite loop because we did not increment the counter for the loop. The counter remains the same through each iteration of the loop and progress is not made towards loop termination. The correct code is shown below.
|
Loops while do...while for Control Structure Loop Design Methodology Common Loop Errors |
||
Fook Yuen Sin - Team 1 |