Skip to content

Commit 23d5b24

Browse files
authored
[Term entry]: Python Keywords: continue
* Term entry: continue keyword in Python * minor content fixes * Update continue.md ---------
1 parent 6104967 commit 23d5b24

File tree

1 file changed

+66
-0
lines changed
  • content/python/concepts/keywords/terms/continue

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
Title: 'continue'
3+
Description: 'Skips the rest of the current loop iteration and moves to the next one immediately.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Conditionals'
9+
- 'Continue'
10+
- 'Control Flow'
11+
- 'Loops'
12+
CatalogContent:
13+
- 'learn-python-3'
14+
- 'paths/computer-science'
15+
---
16+
17+
The **`continue`** keyword in Python is used inside [loops](https://www.codecademy.com/resources/docs/python/loops) to bypass 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.
18+
19+
## Syntax
20+
21+
```pseudo
22+
continue
23+
```
24+
25+
**Parameters:**
26+
27+
The `continue` statement does not take any parameters.
28+
29+
**Return value:**
30+
31+
The `continue` statement does not return any value. It simply skips to the next iteration of the nearest enclosing loop.
32+
33+
> **Note**: Unlike `break`, `continue` does not exit the loop - it only skips the current iteration.
34+
35+
## Example: Using `continue` in a `while` Loop
36+
37+
This example demonstrates how the `continue` statement skips the iteration when the count reaches 3, preventing it from being printed:
38+
39+
```py
40+
count = 0
41+
while count < 5:
42+
count += 1
43+
if count == 3:
44+
continue
45+
print(count, end = ' ')
46+
```
47+
48+
The output of this code is:
49+
50+
```shell
51+
1 2 4 5
52+
```
53+
54+
## Codebyte Example: Skipping Even Numbers Using `continue`
55+
56+
This codebyte example defines a function that prints only odd numbers from 0-9 by using the `continue` statement to skip even numbers in a `for` loop:
57+
58+
```codebyte/python
59+
def odd_numbers():
60+
for n in range(10):
61+
if n % 2 == 0:
62+
continue # Skips even numbers
63+
print(n)
64+
65+
odd_numbers()
66+
```

0 commit comments

Comments
 (0)