Ensure the variable evaluated in the condition is always modified inside the loop body in a direction that moves it closer to the terminating state.
Infinite Loops: What They Are and How to Avoid Them
How can I prevent infinite loops in while loops?
The answer
More FAQs in Infinite Loops: What They Are and How to Avoid Them
An infinite loop is a sequence of instructions that continues to execute endlessly because its terminating condition is never met.
In the terminal, you can usually stop it by pressing Ctrl+C. In an IDE, use the Stop execution button.
A TLE error almost always means your code entered an infinite loop, or your algorithm is too slow (e.g., O(n^2) when O(n) is expected).
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.