0

In Python 3 Why the output is 0 but not 1 when I have this?

i=0 while 1==1: print(i) i+=1 break

30th Nov 2017, 4:59 AM
Yinhao Chen
Yinhao Chen - avatar
2 odpowiedzi
+ 1
1==1 is the same as just using True while True: creates an infinite loop if no end condition within the loop (break) i is equal to 0 when the loop is entered i is then printed which outputs 0 Then 1 is added to i and the new value is set back to the variable i (i +=1) Then the loop is immediately exited with break and no further values are output.
30th Nov 2017, 5:34 AM
ChaoticDawg
ChaoticDawg - avatar
0
@ChaoticDawg Thanks
30th Nov 2017, 11:20 AM
Yinhao Chen
Yinhao Chen - avatar