The following code will output infinite lines of "test".
foo = 5
while foo:
print("bar")
The other day I came across an answer here about digit sums. This was the code shown in the answer:
def digit_sum(t):
s = 0
while t:
s += t % 10
t //= 10
return s
The part I'm focusing on is the "while t:" part. How and why does this work?