Google News
logo
Python Program to Using the continue statement in a for loop
In the following example of Python program that demonstrates how to use the `continue` statement in a `for` loop :
Program :
# Using the continue statement in a for loop
numbers = [1, 2, 3, 4, 5]

for number in numbers:
    if number == 3:
        continue
    print(number)

print("Done.")
Output :
1
2
4
5
Done.
In the above program, we use a `for` loop to iterate over a list of numbers. Inside the loop, we use an `if` statement to check if the current number is equal to `3`. If it is, we use the `continue` statement to skip the rest of the loop body and move on to the next iteration.

When the loop continues, the program executes the `print()` statement outside the loop, which prints the message "Done."

You can use the `continue` statement to skip over specific iterations of a loop based on a condition. In this example, we skip printing the number `3` and continue with the rest of the loop body.