continue is used to skip the current iteration and move to the next one.

example

i = 1
 
while i <= 5:
    if i == 3:
        i += 1
        continue
    print(i)
    i += 1

output

1
2
4
5

Note

  • continue skips the current step
  • The loop does not stop, it moves to the next iteration

Question

Write a program in Python to print all odd numbers from 1 to 10 (without using continue)

i = 1
 
while i <= 10:
    if i % 2 != 0:
        print(i)
    i += 1

output

1
3
5
7
9

Question

Write a program in Python to print all odd numbers from 1 to 10 (using continue)

i = 1
 
while i <= 10:
    if i % 2 == 0:
        i += 1
        continue
    print(i)
    i += 1

output

1
3
5
7
9