while loop may seem easy to write, but it's also very easy to create a so-called infinite loop. For instance, when you forget to increment the value of counter:
counter = 1
while counter <= 10:
print('Current value:', counter)
In the program above, counter will always be equal to 1, so the condition in the
while loop will be always
True. This means, in turn, that the program will try to print
Current value: 1 forever. Your program will run forever, and you will have to force it to quit. Our platform automatically kills long-running programs, but in real life you have to manually force the program to quit.
When you create a loop, always think about its termination condition to avoid situations like the one above.