0% found this document useful (0 votes)
53 views1 page

Python Continue, Break and Pass

The document discusses the continue, break, and pass statements in Python. The continue statement skips the current iteration of a loop, break exits the entire loop, and pass acts as a placeholder without any action.

Uploaded by

Atharva Mahabare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Python Continue, Break and Pass

The document discusses the continue, break, and pass statements in Python. The continue statement skips the current iteration of a loop, break exits the entire loop, and pass acts as a placeholder without any action.

Uploaded by

Atharva Mahabare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

**`continue` statement**:
- When Python encounters a `continue` statement in a loop (like `for` or `while`), it immediately
jumps to the next iteration of the loop.
- It's useful when you want to skip certain iterations of a loop based on a condition without executing
the rest of the loop's code.

2. **`break` statement**:
- When Python encounters a `break` statement in a loop, it immediately exits the loop, regardless of
the loop's conditions.
- It's handy when you want to prematurely exit a loop based on a condition without executing the
remaining iterations.

3. **`pass` statement**:
- The `pass` statement is a null operation, meaning it does nothing.
- It's used as a placeholder when a statement is syntactically required but you don't want any action
to be taken.
- It's often used as a placeholder for code that will be added later.

Here's a simple example to illustrate their usage:

```python
for i in range(1, 6):
if i == 3:
continue # Skips the current iteration when i equals 3
print(i)
```

In this example, the `continue` statement skips printing the number 3.

```python
for i in range(1, 6):
if i == 3:
break # Exits the loop when i equals 3
print(i)
```

In this example, the `break` statement stops the loop when `i` equals 3, so only 1 and 2 are printed.

```python
for i in range(1, 6):
if i == 3:
pass # Does nothing when i equals 3
print(i)
```

In this example, the `pass` statement has no effect on the loop's behavior, so all numbers from 1 to 5
are printed.

You might also like