Friday 4 December 2015

Python: continue statement

‘continue’ statement skips the current iteration of loops like for, while.


test.py
i = 2

while (i < 20):
 i+=2
 if(i%2 != 0):
  continue
 print(i)
 
else:
 print("Exiting loop")
 
print("Finished Execution")

Above program prints all the even numbers up to 20 (exclusive).

$ python3 test.py
4
6
8
10
12
14
16
18
20
Exiting loop
Finished Execution




Previous                                                 Next                                                 Home

No comments:

Post a Comment