Python Continue


Python continue Statement

Python continue is used to skip the current iteration of the loop. It will not terminate the loop, the loop will move to the next iteration.

For this, we use the keyword continue.

Continue with for loop

The continue statement will skip the current iteration of the for loop and the loop will move to the next iteration.

For example, in the below code, in the case of the letter ‘a’, the print statement will not be executed and it will continue printing other characters.

Loop skips letter ‘a’.

In [1]:
name = "Logical"
for letter in name:
    if letter == 'a':
        continue
    print(letter)
L
o
g
i
c
l

Continue with while loop

Same way, the continue statement will skip the current iteration of the while loop and the loop will move to the next iteration.

For example, here also, it will not execute print statement when i = 3, and it will continue with other numbers.

Loop skips number 3.

In [1]:
i = 0

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