+ 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
3 Respostas
+ 1
Inverse the condition to skip the number. Instead of doing ...
if number == 3:
continue
Do this instead
if number != 3
print( number )
+ 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++;
}
0
# you mean like this?
n = 0
while n<10:
n+=1
if n%2==0:
continue
print(n)