+ 1

Guys I tried to use the continuestatement in while loop but when I skipped a number..it shows the number again after skippingit

While loop python

8th Mar 2022, 7:08 AM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
3 Respuestas
+ 1
Inverse the condition to skip the number. Instead of doing ... if number == 3: continue Do this instead if number != 3 print( number )
8th Mar 2022, 7:19 AM
Ipang
+ 1
In while loop you have to increment or decrement the by your self.So if you have incremented after the continue statement it will not increment Ex: n = 0; while(n<10){ if(n%2 == 0) continue; cout << n; n++; } will fall in continuous loop because when n is even it will be continued with increment. To correct it att n++ with continue. n = 0; while(n<10){ if(n%2 == 0) { n++; continue; cout << n; n++; }
8th Mar 2022, 7:36 AM
Hritik
0
# you mean like this? n = 0 while n<10: n+=1 if n%2==0: continue print(n)
8th Mar 2022, 7:20 AM
Ervis Meta
Ervis Meta - avatar