Python while loop


Can someone explain the meaning of “while 1:” in the Python code above? I want to know what is the condition that should be true for this loop to work.

1 Like

The while loop always checks the truthiness of a condition. For example, (5>3) is logically true and (3>5) is logically false . If the condition is false, then the while loop terminates.

In addition to simple Boolean logic, any value can be categorized as truthy or falsy. Truthy values are values that have any value that is not 0. 0 on the other hand is a falsy value. So if you were to use “while 1:” , the condition of the while loop always resolves to true, as the integer value 1 is a truthy value.

TLDR; We use while 1: to denote that the loop is never ending, and can only be terminated by using a break statement.

I got it. Thank you so much. :blush:

1 Like