Replies To: Can someone advise me on how to deal with infinite loops.

Re: Can someone advise me on how to deal with infinite loops.

Posted 24 January 2012 - 02:31 PM

Infinite loops are logic problems. All loops have conditions. As long as those conditions evaluate to true, the loop will continue. You can either use a break statement to break out of the loop, or change the variables so the condition evaluates to false.

Re: Can someone advise me on how to deal with infinite loops.

Posted 24 January 2012 - 02:36 PM

The loop will iterate according to what condition you have given to it. So if you tell it to loop while x > y. This means it will loop until this condition fails.
So if you want to make sure you are not getting infinite loop, then you have to make sure there is a possibility that after some iterations, your condition will be false! That is the way to deal, so look at your code and think why my condition is not getting false? may be the variables are not updated in the loop or anything that prevent the loop condition variables from changing will cause an infinite condition.
For your special case, may be show us your code where the infinite loop was occurring, and we may be able to help