The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.
As long as the condition that follows the while
keyword is true, the block following the while
statement will continue to be executed over and over again.
Syntax of While loop
while <expr>:
<statements>
Example:
while True:
print("working...")
The easiest way to specify an infinite loop in Python is to use the while
keyword with an expression that is always true.