0

Continue loop doubt?

In this case When 3 comes print skipping 3 So why in another 3 is printed https://code.sololearn.com/cqunRttKwO42/?ref=app

30th May 2021, 9:34 AM
Aayush Jat
Aayush Jat - avatar
3 ответов
+ 5
In your loop you are printing at first i. i = 2 -> print 2 i gets 3 -> print skipping i continue jumps just to the beginning of the loop but does not change i. A while loop is not a for loop. i is still 3 -> print(3) i gets 4 If you want to work with continue in a while loop: if i == 3: i += 1 continue But I would say it makes no sense to use continue in a while loop.
30th May 2021, 9:46 AM
Denise Roßberg
Denise Roßberg - avatar
+ 5
i think it should be like that: ▪︎for output there is one print() in the if... clause -> 'Skipping...' ▪︎and the other one is in the else... clause -> print number i = 1 while i<=5: if i==3: print("Skipping 3") else: print(i) i+=1
30th May 2021, 3:17 PM
Lothar
Lothar - avatar
+ 1
You aren't actually skipping print(i) on line 3, so that prints all numbers. Also, continue starts the next iteration of the loop, so having it as last statement in the loop doesn't change anything
30th May 2021, 9:43 AM
Benjamin Jürgens
Benjamin Jürgens - avatar