continue statement skips the rest of the code inside a loop for the current iteration in a Loop and jumps the program execution to the beginning of the enclosing loop.
continue statement is inside a nested loop (one loop inside another loop), the
continue statement skips only the current iteration of the enclosing loop.
continue Statement Example
Gives is a Python program which iterates over a list of numbers and prints only odd numbers.
The if statement‘s conditional expression checks for the number if the current number is odd or even. When an even number is checked, the
continue statement is executed and program execution jumps to the beginning of the loop.
In case of odd numbers, the program prints the number into the console.
for i in [1,2,3,4,5,6]: if i % 2 == 0: continue print(i, " ") print("Statement after loop body")
1 3 5 Statement after loop body
The flowchart of the
continue statement in a Python for loop.
Happy Learning !!