# continue

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

{% hint style="success" %}
([..](https://lochiwei.gitbook.io/web/js/grammar/statement "mention")) <mark style="color:yellow;">**skip**</mark> to the <mark style="color:yellow;">**next**</mark> [iteration](https://lochiwei.gitbook.io/web/js/iteration "mention") of the <mark style="color:orange;">**current**</mark>**&#x20;**<mark style="color:yellow;">**/**</mark> [**labeled**](https://lochiwei.gitbook.io/web/js/grammar/statement/other/label) [loop](https://lochiwei.gitbook.io/web/js/grammar/statement/loop "mention").

```javascript
continue;          // skips to next iteration of current loop
continue label;    // skips to next iteration of labeled loop
```

{% endhint %}

{% tabs %}
{% tab title="🧨 雷區" %}
{% hint style="danger" %} <mark style="color:purple;">**continue**</mark> <mark style="color:yellow;">**statement**</mark> can be used <mark style="color:red;">**only**</mark>**&#x20;**<mark style="color:yellow;">**within the body of**</mark> a [loop](https://lochiwei.gitbook.io/web/js/grammar/statement/loop "mention"), using it <mark style="color:yellow;">**anywhere**</mark>**&#x20;**<mark style="color:red;">**else**</mark> causes a [<mark style="color:red;">**SyntaxError**</mark>](https://lochiwei.gitbook.io/web/js/err/syntax).
{% endhint %}
{% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="success" %} <mark style="color:yellow;">**nested**</mark> [loop](https://lochiwei.gitbook.io/web/js/grammar/statement/loop "mention")

* [**labeled**](https://lochiwei.gitbook.io/web/js/grammar/statement/other/label) <mark style="color:yellow;">**statement**</mark> is <mark style="color:red;">**needed**</mark> when you want to <mark style="color:purple;">**skip**</mark> <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").
  {% endhint %}

{% hint style="warning" %}
[break](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/break "mention")/<mark style="color:purple;">**continue**</mark> <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> [loop](https://lochiwei.gitbook.io/web/js/grammar/statement/loop "mention")/[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 %}

{% hint style="success" %}
[label](https://lochiwei.gitbook.io/web/js/grammar/statement/other/label "mention") is <mark style="color:red;">**only**</mark>**&#x20;**<mark style="color:yellow;">**used by**</mark> [break](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/break "mention") <mark style="color:yellow;">**/**</mark> <mark style="color:purple;">**continue**</mark>.
{% endhint %}

{% hint style="danger" %}
if the <mark style="color:yellow;">**code**</mark> you need to <mark style="color:yellow;">**wrap**</mark> a [scope](https://lochiwei.gitbook.io/web/js/scope "mention") <mark style="color:yellow;">**around**</mark> has [return](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/return "mention"), [this](https://lochiwei.gitbook.io/web/js/concept/execution-context/this "mention"), [break](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/break "mention"), or [continue](https://lochiwei.gitbook.io/web/js/grammar/statement/flow/jump/continue "mention") in it, <mark style="color:red;">**don't**</mark>**&#x20;**<mark style="color:yellow;">**use**</mark> a [func](https://lochiwei.gitbook.io/web/js/val/func "mention")/[iife](https://lochiwei.gitbook.io/web/js/val/func/expr/iife "mention")(which has <mark style="color:yellow;">**its own**</mark> [boundary](https://lochiwei.gitbook.io/web/js/val/func/boundary "mention")), use a [block](https://lochiwei.gitbook.io/web/js/grammar/statement/other/block "mention") instead❗️

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

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

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

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

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

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

* [ ] [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements) ⟩ [control flow](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#control_flow) ⟩ [continue](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue) ⭐️
* [ ] [Loops and iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration) ⟩ [continue statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#continue_statement)
  {% endtab %}
  {% endtabs %}
