Computer >> Computer tutorials >  >> Programming >> Python

How to use continue statement in Python loop?


The loop control statement continue abandons the pending statements in current iteration of the looping block and starts next iteration. The continue statement appears in a conditional block inside loop

Example

x=0
while x<10:
     x=x+1
     if x==5: continue
     print ('x=',x)

The output shows that when x is 5 the print statement is not executed and next iteration is undertaken printing from x=6 onwards

Output

x= 1
x= 2
x= 3
x= 4
x= 6
x= 7
x= 8
x= 9
x= 10