Skip to content

[Term entry]: Python keywords: continue #7027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions content/python/concepts/keywords/terms/continue/continue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
Title: 'continue'
Description: 'Skips the rest of the current loop iteration and moves to the next one immediately.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
Tags:
- 'Conditionals'
- 'Continue'
- 'Control Flow'
- 'Loops'
CatalogContent:
- 'learn-python-3'
- 'paths/computer-science'
---

The **`continue`** keyword is used inside [loops](https://www.codecademy.com/resources/docs/python/loops) to skip the remaining code in the current iteration and immediately begin the next one. When Python encounters `continue`, it jumps to the next iteration without executing the remaining statements in the loop body. This allows certain conditions to bypass parts of the loop without exiting it completely. It is useful for filtering out unwanted values, skipping invalid data, or focusing on specific cases within loops.

```pseudo
continue
```

**Parameters:**

The `continue` statement does not take any parameters.

**Return value:**

The `continue` statement does not return any value. It simply skips to the next iteration of the nearest enclosing loop.

> **Note**: Unlike `break`, `continue` does not exit the loop - it only skips the current iteration.

## Example: Using `continue` in a `while` Loop

This example demonstrates how the `continue` statement skips the iteration when the count reaches 3, preventing it from being printed:

```py
count = 0
while count < 5:
count += 1
if count == 3:
continue
print(count, end = ' ')
```

The output of this code is:

```shell
1 2 4 5
```

## CodeByte Example: Skipping Even Numbers Using `continue`

This example defines a function that prints only odd numbers from 0 to 9 by using the `continue` statement to skip even numbers in a `for` loop:

```codebyte/python
def odd_numbers():
for n in range(10):
if n % 2 == 0:
continue # Skips even numbers
print(n)

odd_numbers()
```