I was just writing a little python program to run the Collatz algorithm and I think the while loop isn't breaking when it should. I'm running this whith VSCode 1.44.2 and Python 3.7.5 64bit
def collatz(n):
while n != 1.0:
if n%2 == 0:
n = n/2
else:
n = 3*n+1
print(n)
collatz(n)
collatz(3)
and here is the complete output
10
5.0
16.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
16.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
5.0
16.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
16.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
8.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
4.0
2.0
1.0
1.0
2.0
1.0
1.0
The program ended at this point without an error. When I step through the program I see a message "(return) collatz: None" when n=1.0 and the next debugger step goes to the beginning of the while loop again. Why isn't the program ending at this point? Since it's not ending when n=1, why does it end eventually and doesn't run forever?