i = 1 while i<=5: print(i) i+=1 if i==3: print("Skipping 3") continue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

i = 1 while i<=5: print(i) i+=1 if i==3: print("Skipping 3") continue

Explain me this pls

1st Sep 2020, 6:54 PM
Henok
Henok - avatar
6 Answers
+ 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.
1st Sep 2020, 6:59 PM
shubham kumar
shubham kumar - avatar
+ 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.
1st Sep 2020, 9:03 PM
Lothar
Lothar - avatar
+ 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.
1st Sep 2020, 7:02 PM
shubham kumar
shubham kumar - avatar
+ 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
1st Sep 2020, 7:38 PM
Nathan Sikati
Nathan Sikati - avatar
0
WHY DOES MY OUTPUT COME OUT LIKE THIS WHEN I HAVE DONE CONTUNUE?? 1 2 skipping 3 3 4 5
1st Apr 2021, 7:12 PM
hulu hulu
hulu hulu - avatar
0
i=1 while i<=5: i+=1 print(1)
27th Mar 2023, 12:57 AM
Rahil
Rahil - avatar