How to use continue statement in Python loop?

PythonServer Side ProgrammingProgramming

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
raja
Published on 17-Feb-2018 13:40:32
Advertisements