# no-explicit-iterator-in-for-of

Disallow explicit iterator calls in for-of loops

A for-of loop obtains an iterable's iterator automatically.
Instead, you SHOULD iterate over the iterable directly.

- Category: style
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function sum(values: int32[]): int32 {
    let total: int32 = 0;
    for (const value of values.iterator()) {
        total += value;
    }
    return total;
}
```

## Accepted

```ds title="main.ds"
function sum(values: int32[]): int32 {
    let total: int32 = 0;
    for (const value of values) {
        total += value;
    }
    return total;
}
```

## Prior art

- [Clippy · explicit_iter_loop](https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop)

[language/linter/src/rules/style/no_explicit_iterator_in_for_of.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/no_explicit_iterator_in_for_of.rs#L8)
