+ 3
Please break this While loop down step by step !
i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished")
1 Antwort
+ 3
You start the loop with i = 0
The first thing that happens is you increment i
i = i + 1 or i = 1
now you test if i (or 1) equals 2
No so you try the same with 5
And no again
Now you print i
Output: 1
Loop around and start with a increment
i = 1 + 1 or i = 2
test if i (or 2) equals 2
Output: "Skipping 2"
Yes skip all code and start again
Now i = 3
You test if i equals 2 or 5 and both say no so you just print i and go on
Output:
3
4
And now the 5th iteration starts and you test if i (or 5) equals 5
Yes so print
Output: "Breaking"
And stop the loop
And at last print
Output: "Finished"