+ 1
I cant understand its result
i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished")
3 odpowiedzi
+ 4
while True:
^That's an infinite loop. It'll keep the loop going endlessly until you break it by setting up some sort of condition inside of the code.
In this case, it'll break once variable 'i' reaches a value of 5.
At the beginning of the loop, variable 'i' is being increased by 1. It checks if i is equal to 2, if it is then it prints that it's skipping and uses 'continue' which forces the loop to go into the next iteration of itself. If it isn't equal to 2, it then checks if it is equal to 5, and if it is print "breaking" and break out of the loop. If it isn't equal to 2 or 5, then it'll simply print the value of 'i' and go into its next loop iteration.
Once the loop is broken, it'll print "Finished" and end the program.
:::: OUTPUT :::::
1
Skipping 2
3
4
Breaking
Finished
+ 2
@Ace's is helpful!