LoginSignup
0
0

More than 5 years have passed since last update.

[メモ]javascriptのbreak、continueで使うラベル

Posted at

javascript勉強中の修行僧です:innocent:

jsにはfor文やwhile文でラベルというものが使えます。
これを使えば指定のループまでcontinue,breakでジャンプすることができます。

ラベルを使ってみる

外側のwhile文にouter_loopというラベルを付けます。
ラベルを使えば、入れ子のループを同時に抜けることができます。

outer_loop:
while(true){
  "outer_loop";
  while(true){
    "inner_loop";
    break outer_loop;
  }
}

jsにはこんなのがあるんですね:hugging:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0