1

I understand this code:

c = 5

while c != 0:
    print(c)
    c -= 1

Output will be:

5
4
3
2
1

But eventually the code below:

c = 5

while c:
    print(c)
    c -= 1

Gave me the same result.

I've read something about conversion into bool automatically? Does compiler knows if c > 0 then it would be true for the while loop, and if c = 0 then it would be false?

Stefan0309
  • 1,602
  • 5
  • 23
  • 61

0 Answers0