A number of folks have mentioned a fix by removing exit() but let's dive into why you are seeing what you're seeing with a simpler example:. However, an infinite loop may actually be useful. Now control returns to the condition; i is still 0, so the loop body executes again, printing a 0 . When Python gets to the loop, i will be 0, which is less than 10, so the loop body executes, printing a 0. Use the len() function to determine the length of the list, then start at 0 and loop your way through the list items by refering to their indexes. Fret not, in this article, I shall include an example for an infinite while loop and some common examples that use if-else or break statement coupled with the while loop. The infinite while loop in Python. It might be surprising for you. Let us understand how we can use a break statement in a for loop using an example. While the loop is skipped if the initial test returns FALSE, it is also forever repeated infinitely if the expression always returns TRUE. More on that here. The usage of for loop in python is similar to most of the other programming languages, using the for loops, it’s just that syntactically the use of for keyword in python is different in Python. When the conditional expression is empty, it is assumed to be true. Let’s start working with a nested while loop in this case. This results in a loop that never ends. There are several ways to construct a sequence of values and to save them as a Python list. In Python, there is no C style for loop, i.e., for (i=0; i