Chapter 24: Infinite loop

In some scenarios, running an infinite loop is necessary based on the program's logic. However, it's recommended to include a condition to break the loop; otherwise, the script may run indefinitely and potentially impact the production environment. In this example, we are intentionally creating an infinite loop using the true Boolean expression. To stop this loop during learning or testing, we use Ctrl + C on the keyboard. However, in real-world usage, it's important to implement a proper break condition to avoid unintended consequences.

 

#running infinite loop
num = 0
while True:
    print(num)
    num += 1