The continue statement is used within a loop to skip the rest of the statements in the body of loop for the current iteration and jump to the start of the loop for next iteration. The break and continue statements are opposite each other which are used to change the flow of loop, break terminates the loop when a condition is got and continue leave out the current iteration. The continue statement is used in both while and for loops. To contine in a loop we can use the continue keyword.
In other words we can say that the continue statement in python return the control to beginning of the control loop.
Syntax:
continue
Syntax for while loop:
while expression:
statement
if condition:
continue
statement
Syntax for for loop:
for value in range:
statement
if condition:
continue
statement
Flow diagram
Example:
program to display only odd numbers
for n in [10, 13, 9, 68, 4, 91, 54]:
if n%2 == 0:
continue
print(n)
Output:
13
9
91
Continue Statement in Python Video:
Comments