Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Continue while loop in Python

Below is my code for continue while loop. I’m getting the correct o/p after passing the continue statement.

#!/usr/bin/python
# -*- coding: utf-8 -*-
i = 0
while i <= 6:
    i += 1
    if i == 3:
        continue
    print i

O/p:

1
2
4
5
6
7

my confusion is while i<=6, so o/p should be 1,2,4,5,6. how its going for the next interation, 7 is greater than 6 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This has nothing to do with continue. You are printing after i+=1. So, if iteration starting when i=6 is the last one, then in that same iteration, i becomes i=7 after i+=1, and is printed as is

i=0
while i<=6:
   i+=1
   print(i)

also displays 1 to 7.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading