- 3
In the continue statement in while loop...while do they state the number after you have skipped it
While loop
18 Respuestas
+ 2
Just to be clear. A "continue" statement is just a place holder statement, where the absence of a statement is a syntax error. It doesn't let you skip the loop.
If you want to break out of a loop. Then you need to use "break".
+ 1
Mustafa A
I just tried it again it worked...I copied your code.
Thank you very much I appreciate
+ 1
Mustafa A I have copied it
0
I get you but when I use the continue statement, it still shows the number which I skipped
0
Okundaye Jesse Eghosasere Share the code. I don't understand what you mean.
0
a = 2
while a <= 20:
print(a)
a = a + 1
if a == 4:
print("skipping 4")
continue
Mustafa A
0
Okundaye Jesse Eghosasere Having a continue statement there does nothing at all.
If you want to skip 4 then increase "a" again by 1 when "a == 4". Then, the next value will be 5.
0
Mustafa A
Please I don't get...can you share a code for it...because when I did mine 4 still appeared
0
Okundaye Jesse Eghosasere
a = 2
while a <= 20:
print(a)
a += 1
if a == 4:
print("skipping 4")
a += 1
0
Mustafa A
I just tried this the output was
1
2
3
"Skipping 4"
4
5
6
7
8
9
10
And ends at 20
Why did 4 still appeared
0
Okundaye Jesse Eghosasere Check your indentation. This doesn't make any sense. The print starts at 1 when the lowest "a" gets is 2.
0
Okundaye Jesse Eghosasere At a look at this: https://code.sololearn.com/cV5971QIgEn2/?ref=app
0
Okundaye Jesse Eghosasere Copy the code and let me know. I am going to delete it afterwards.
0
Okundaye Jesse Eghosasere You're welcome.
0
Mustafa A
Why was the a = a + 1 nested within the if clause instead of the while loop
0
Okundaye Jesse Eghosasere Because you want to apply the condition to add one more (skip the current a) when a == 4. If it's not inside the if statement, the condition won't apply. A will increase with one more for every a.
0
Okay....I understand now
Thanks Mustafa A