# loop

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [statement](https://lochiwei.gitbook.io/web/js/grammar/statement) ⟩ loop

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

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

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

👉 [continue-vs.-break](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/continue-vs.-break "mention")
{% endhint %}

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

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

* when you want to [**skip**](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/continue) <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](https://lochiwei.gitbook.io/web/js/grammar/statement/loop "mention").
* when you want to [break](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/break "mention") <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](https://lochiwei.gitbook.io/web/js/grammar/statement/loop "mention") <mark style="color:yellow;">**/**</mark> [switch](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/branch/switch "mention").
  {% endhint %}

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

📗 [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](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/while "mention") <mark style="color:yellow;">**/**</mark> [do...while](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/do...while "mention")
  * [for](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/for "mention")： [for](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/for/for "mention") <mark style="color:yellow;">**/**</mark> [of](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/for/of "mention") <mark style="color:yellow;">**/**</mark> [in](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/for/in "mention") <mark style="color:yellow;">**/**</mark> [await](https://lochiwei.gitbook.io/web/js/grammar/statement/loop/for/await "mention")
    {% endtab %}

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

* [iteration](https://lochiwei.gitbook.io/web/js/iteration "mention")
  {% endtab %}

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

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