> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Break-Or-Continue-Outside-Loop

#### Sourcery rule id: `break-or-continue-outside-loop`

#### Description

Remove break or continue statement found outside for or while loop


#### Before

```python
def handle_invalid_number(numbers):
    for number in numbers:
        if is_valid(number):
            continue
    break
    handle(number)
```

#### After

```python
def handle_invalid_number(numbers):
    for number in numbers:
        if is_valid(number):
            continue
    handle(number)
```



#### Explanation

The [`break`](https://docs.python.org/3/reference/simple_stmts.html#break) and
[`continue`](https://docs.python.org/3/reference/simple_stmts.html#the-continue-statement)
are used to control the behaviour of
[`for`](https://docs.python.org/3/reference/compound_stmts.html#the-for-statement)
and
[`while`](https://docs.python.org/3/reference/compound_stmts.html#the-while-statement)
loops. Using them outside those loops is a
[`SyntaxError`](https://docs.python.org/3/library/exceptions.html#SyntaxError).

This error may be very easy to pass through since sometimes it is caused by a
wrong indentation.
