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 ?
>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.