+ 1
i = 1 while i<=5: print(i) i+=1 if i==3: print("Skipping 3") continue
Explain me this pls
6 ответов
+ 2
For the first time when i=1;
Output:1;
Next time it will be 2
Next time when it will be 3,it will print Skipping 3 instead of 3
Next time 4 will be output
Last time 5 will be output.
+ 7
As already mentioned, continue is not needed and can be omitted. It is the last statement in the while loop, so the program flow will move automatically to the head of while loop.
+ 2
Continue statement will skip for that value usually but here if will read the skipping 3 statement and go for the next loop value.
+ 2
The continue is not important of there is nothing after, every way, the next step is the while line.
continue would bé important if print(i) was after the if condition
0
WHY DOES MY OUTPUT COME OUT LIKE THIS WHEN I HAVE DONE CONTUNUE??
1
2
skipping 3
3
4
5
0
i=1 while i<=5: i+=1 print(1)