# \*closedRange()

[JS](../../..)⟩ [iteration](../..) ⟩ [custom generators]() ⟩ \*closeRange()

{% tabs %}
{% tab title="💾 程式" %}
:floppy\_disk: replit：[closed range (generator)](https://replit.com/@pegasusroe/ClosedRange-generator#index.js)

👉 compare： [closedrange](../../iterable/custom/closedrange "mention") (the hard way), [list](list "mention")

```javascript
// ⭐️ (closed) range of integers
function* closedRange(start, end) {
    for (let i = start; i <= end; i++) { yield i }
}
```

💈範例：

```javascript

for (const i of closedRange(1, 3)) console.log(i);  // 1 2 3
[...closedRange(-2, 2)],                            // [ -2, -1, 0, 1, 2 ]
```
{% endtab %}

{% tab title="👥 相關" %}
* [closedrange](../../iterable/custom/closedrange "mention") - range of integers (the hard way)
* [list](list "mention") - finite arithmetic sequence
* [integers](integers "mention") - infinite non-negative integers
* <mark style="color:yellow;">**import**</mark> [iterator](../../iterator/iterator "mention") to <mark style="color:yellow;">**extend**</mark> built-in [iterator](../../iterator "mention")s.
{% endtab %}
{% endtabs %}
