+ 1

What does "break" mean in this code?

i = 0 while 1==1: print(i) i = i + 1 if i >= 5: print("breaking") break print("Finished")

12th Nov 2018, 6:04 AM
Christopher Wong
Christopher Wong - avatar
2 Réponses
+ 11
Break will break this loop. In simple words, loop will end on reaching break and code outside loop will execute.
12th Nov 2018, 6:12 AM
Arushi Singhania
Arushi Singhania - avatar
+ 6
It breaks out of the while loop if i >= 5.
12th Nov 2018, 6:12 AM
Paul
Paul - avatar