---
title: "U2040: A statement after `stop` or `skip` in the same block, which never runs"
url: https://una-lang.org/en/docs/errors/U2040/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U2040.md
---

# U2040: A statement after `stop` or `skip` in the same block, which never runs

A statement comes after `stop` or `skip` in the same block, so it never runs.

## Why Una rejects it

In edition 0.4, `stop` ends the innermost loop and `skip` ends the current iteration (`spec/26 §3`, ADR 0116 rule 6). A statement after an unconditional `stop` or `skip` in the same block can never run, which is almost always a mistake: the statement was meant to come before the exit, or under a condition. The checker refuses it, at the first such statement.

`stop when c` is conditional, so statements after it run whenever `c` is false and stay legal.

Statements after the block that holds the `stop` or `skip`, such as those after an `if` whose block ends in `skip`, run on the other paths and stay legal too.

## How to fix it

The repair removes the statements after the exit.

## The repair at a glance

`src/demo.una`

```diff
  module demo

  pub positives(xs: List[Int]) -> Int
  =
    let edit count = 0
    for x in xs
      if x <= 0
        skip
-       count = count - 1
      count = count + 1
    count
```

## Failing example

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

pub positives(xs: List[Int]) -> Int
=
  let edit count = 0
  for x in xs
    if x <= 0
      skip
      count = count - 1
    count = count + 1
  count
```

## Fixed example

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

pub positives(xs: List[Int]) -> Int
=
  let edit count = 0
  for x in xs
    if x <= 0
      skip
    count = count + 1
  count
```
