# E0018

Warning name: `useless_loop`

There is no `continue` in this loop expression, so `loop` is useless here.

This error occurs when using a `loop` expression that contains no `continue`
statement. In MoonBit, a `loop` without any `continue` statements is equivalent
to an block expression that will be executed only once, making the `loop`
keyword redundant in such cases. You should either add a `continue` statement if
you need to restart the loop from the beginning, or use a simpler control flow
construct like `match` or `if`.

## Erroneous example

```{literalinclude} /sources/error_codes/0018_error/top.mbt
:language: moonbit
:start-after: start example
:end-before: end example
:prepend: "///|\nfn main {"
:append: "}"
```

Output:

```{literalinclude} /sources/error_codes/0018_error/__snapshot__/snapshot
```

## Suggestion

Either add a `continue` statement if you need to restart the loop:

```{literalinclude} /sources/error_codes/0018_fixed/example_0.mbt
:language: moonbit
:start-after: start example
:end-before: end example
:prepend: "///|\nfn main {"
:append: "}"
```

Output:

```{literalinclude} /sources/error_codes/0018_fixed/__snapshot__/snapshot_0
```

Or use `if`/`match` you don't need to use `continue`:

```{literalinclude} /sources/error_codes/0018_fixed/example_1.mbt
:language: moonbit
:start-after: start example
:end-before: end example
:prepend: "///|\nfn main {"
:append: "}"
```

Output:

```{literalinclude} /sources/error_codes/0018_fixed/__snapshot__/snapshot_1
```
