> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/grammar/statement/loop.md).

# loop

a statement that does something repeatedly.

[JS](/web/js.md) ⟩ [statement](/web/js/grammar/statement.md) ⟩ loop

{% hint style="success" %}
([statement](/web/js/grammar/statement.md)) does something <mark style="color:yellow;">**repeatedly**</mark>.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}

* [continue](/web/js/grammar/statement/flow/jump/continue.md) ： <mark style="color:yellow;">**skips**</mark> to the <mark style="color:yellow;">**next**</mark> [iteration](/web/js/iteration.md) of the <mark style="color:yellow;">**current**</mark>/[labeled](/web/js/grammar/statement/other/label.md) [loop](/web/js/grammar/statement/loop.md).
* [break](/web/js/grammar/statement/flow/jump/break.md)：<mark style="color:yellow;">**breaks**</mark> the <mark style="color:yellow;">**current**</mark> [loop](/web/js/grammar/statement/loop.md) / [switch](/web/js/grammar/statement/flow/branch/switch.md) <mark style="color:yellow;">**or**</mark> [**labeled**](/web/js/grammar/statement/other/label.md) statement <mark style="color:red;">**entirely**</mark>:exclamation:

👉 [continue vs. break](/web/js/grammar/statement/flow/jump/continue-vs.-break.md)
{% endhint %}

{% hint style="warning" %}
(<mark style="color:yellow;">**nested**</mark> <mark style="color:purple;">**loop**</mark>)

[**labeled**](/web/js/grammar/statement/other/label.md) <mark style="color:yellow;">**statement**</mark> is <mark style="color:red;">**needed**</mark>&#x20;

* when you want to [**skip**](/web/js/grammar/statement/flow/jump/continue.md) <mark style="color:yellow;">**to**</mark> the <mark style="color:yellow;">**next iteration**</mark> of <mark style="color:yellow;">**an outer loop**</mark> that is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**the**</mark>**&#x20;**<mark style="color:red;">**nearest**</mark>**&#x20;**<mark style="color:yellow;">**enclosing**</mark> [loop](/web/js/grammar/statement/loop.md).
* when you want to [break](/web/js/grammar/statement/flow/jump/break.md) <mark style="color:yellow;">**out**</mark> <mark style="color:yellow;">**of**</mark> a statement that is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**the**</mark>**&#x20;**<mark style="color:red;">**nearest**</mark>**&#x20;**<mark style="color:yellow;">**enclosing**</mark> [loop](/web/js/grammar/statement/loop.md) <mark style="color:yellow;">**/**</mark> [switch](/web/js/grammar/statement/flow/branch/switch.md).
  {% endhint %}

{% hint style="warning" %}
[break](/web/js/grammar/statement/flow/jump/break.md)/[continue](/web/js/grammar/statement/flow/jump/continue.md) <mark style="color:red;">**won't**</mark> operate <mark style="color:yellow;">**across**</mark> an [IIFE](/web/js/val/func/expr/iife.md) <mark style="color:yellow;">**function boundary**</mark> to control an <mark style="color:yellow;">**outer**</mark> <mark style="color:purple;">**loop**</mark>/[block](/web/js/grammar/statement/other/block.md).

📗 [You Don't Know JS Yet: Scopes & Closrues](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch6.md#invoking-function-expressions-immediately)
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}

* <mark style="color:yellow;">**loops**</mark>
  * [while](/web/js/grammar/statement/loop/while.md) <mark style="color:yellow;">**/**</mark> [do...while](/web/js/grammar/statement/loop/do...while.md)
  * [for loops](/web/js/grammar/statement/loop/for.md)： [for](/web/js/grammar/statement/loop/for/for.md) <mark style="color:yellow;">**/**</mark> [for-of](/web/js/grammar/statement/loop/for/of.md) <mark style="color:yellow;">**/**</mark> [for-in](/web/js/grammar/statement/loop/for/in.md) <mark style="color:yellow;">**/**</mark> [for-await](/web/js/grammar/statement/loop/for/await.md)
    {% endtab %}

{% tab title="👥 相關" %}

* [iteration](/web/js/iteration.md)
  {% endtab %}

{% tab title="📘 手冊" %}

* [ ] [Loops and iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration)
  {% endtab %}
  {% endtabs %}
