+ 1
why output showing 7 also ?
i = 0 while True: i = i + 1 print(i) if i > 6: print("Breaking") break print("Finished")
2 Respostas
+ 3
Hey MV Phaneendra
First it will print 7 , then your if-condition will execute
First apply condition then execute statement.
if i <= 6:
print(i)
else:
print("Breaking")
break
+ 3
You are printing before testing i > 6. Test first then print. That way it will break at 7 but not print 7. Try this:
i = 0
while True:
i = i + 1 # why not use i += 1?
if i > 6:
print("Breaking")
break
print(i)
print("Finished")