From 6ef1fa4618e08426b874529619a66adbd3d1fcf0 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:07:59 +0100 Subject: unslug ja: move --- .../loop_statements/break_statement/index.html | 24 +++++++++++ .../loop_statements/continue_statement/index.html | 46 ++++++++++++++++++++ .../do...while_statement/index.html | 19 ++++++++ .../guide/loop_statements/for_statement/index.html | 50 ++++++++++++++++++++++ .../javascript/guide/loop_statements/index.html | 17 ++++++++ .../loop_statements/label_statement/index.html | 19 ++++++++ .../loop_statements/while_statement/index.html | 35 +++++++++++++++ 7 files changed, 210 insertions(+) create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/break_statement/index.html create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/continue_statement/index.html create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/do...while_statement/index.html create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/for_statement/index.html create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/index.html create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/label_statement/index.html create mode 100644 files/ja/orphaned/web/javascript/guide/loop_statements/while_statement/index.html (limited to 'files/ja/orphaned/web/javascript/guide/loop_statements') diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/break_statement/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/break_statement/index.html new file mode 100644 index 0000000000..35cc94abdf --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/break_statement/index.html @@ -0,0 +1,24 @@ +--- +title: break 文 +slug: Web/JavaScript/Guide/Loop_Statements/break_Statement +--- +

break 文

+

break 文は loop 文や switch 文、label 文から抜け出すために使用します。

+ +

break 文は次のように使用します。

+
    +
  1. break;
  2. +
  3. break label;
  4. +
+

1番目の形式の構文は最も内側のループもしくは switch から抜けます。2番目の形式の構文は指定した label 文から抜けます。

+


+ 次の例は、その値が theValue である要素のインデックスが見つかるまで、配列の要素について繰り返します。

+
for (i = 0; i < a.length; i++) {
+   if (a[i] == theValue)
+      break;
+}
+
+

{{ PreviousNext("JavaScript/Guide/Loop_Statements/label_Statement", "JavaScript/Guide/Loop_Statements/continue_Statement") }}

diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/continue_statement/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/continue_statement/index.html new file mode 100644 index 0000000000..f7a5697eeb --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/continue_statement/index.html @@ -0,0 +1,46 @@ +--- +title: continue 文 +slug: Web/JavaScript/Guide/Loop_Statements/continue_Statement +--- +

continue 文

+

continue 文は while 文、do-while 文、for 文、label 文をリスタートさせるために用います。

+ +

continue 文は次のように使用します。

+
    +
  1. continue
  2. +
  3. continue label
  4. +
+

例 1
+ 次の例では、i の値が 3 のときに実行される continue 文を用いた while ループを示します。こうすることで n は順に 1、3、7、12 という値をとります。

+
i = 0;
+n = 0;
+while (i < 5) {
+   i++;
+   if (i == 3)
+      continue;
+   n += i;
+}
+
+

例 2
+ checkiandj というラベルの付いた文の中に checkj というラベルの付いた文があります。continue に出くわすと、プログラムは checkj の現在の反復を終了し、次の反復を始めます。continue に出くわすたびに、条件が false になるまで checkj を繰り返します。false が返されると checkiandj 文の残りを完了し、条件が false を返すまで checkiandj を繰り返します。false が返されると checkiandj に続く文が実行されます。

+

continuecheckiandj というラベルを持っているとプログラムは checkiandj 文の最初から続けます。

+
checkiandj :
+   while (i < 4) {
+      document.write(i + "<br/>");
+      i += 1;
+      checkj :
+         while (j > 4) {
+            document.write(j + "<br/>");
+            j -= 1;
+            if ((j % 2) == 0)
+               continue checkj;
+            document.write(j + " is odd.<br/>");
+         }
+      document.write("i = " + i + "<br/>");
+      document.write("j = " + j + "<br/>");
+   }
+
+

{{ PreviousNext("JavaScript/Guide/Loop_Statements/break_Statement", "JavaScript/Guide/Object_Manipulation_Statements") }}

diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/do...while_statement/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/do...while_statement/index.html new file mode 100644 index 0000000000..6e1df1e586 --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/do...while_statement/index.html @@ -0,0 +1,19 @@ +--- +title: do...while 文 +slug: Web/JavaScript/Guide/Loop_Statements/do...while_Statement +--- +

do...while 文

+

do...while 文は指定した条件が false に評価されるまで繰り返します。do...while 文は次のように使用します。

+
do
+   statement
+while (condition);
+
+

statement は条件がチェックされる前に一度実行されます。複数の文を実行するにはブロック文 ({ ... }) を使用して文をグループ化してください。condition が true の場合、その文が再び実行されます。毎回実行された後に条件がチェックされます。条件が false ときは実行が停止され、コントロールが do...while の後に続く文に渡されます。

+


+ 次の例では do ループは最低 1 回は反復され、i が 5 より小さくなくなるまで反復されます。

+
do {
+   i += 1;
+   document.write(i);
+} while (i < 5);
+
+

{{ PreviousNext("JavaScript/Guide/Loop_Statements/for_Statement", "JavaScript/Guide/Loop_Statements/while_Statement") }}

diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/for_statement/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/for_statement/index.html new file mode 100644 index 0000000000..b2dccec25b --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/for_statement/index.html @@ -0,0 +1,50 @@ +--- +title: for 文 +slug: Web/JavaScript/Guide/Loop_Statements/for_Statement +--- +

for 文

+

for ループは指定した条件が false に評価されるまで繰り返します。JavaScript の for ループは Java や C の for ループに似ています。for 文は次のように使用します。

+
for ([initialExpression]; [condition]; [incrementExpression])
+   statement
+
+

for ループを実行すると以下のことが起こります。

+
    +
  1. 初期化式 initialExpression があれば実行されます。この式は通常、1 つかそれ以上のループカウンタを初期化しますが、構文的にはある程度複雑な式も指定できます。また、この式は変数を宣言することもできます。
  2. +
  3. condition 式が評価されます。condition の値が true であればループ文が実行されます。condition が false の場合は for ループは終了します。condition 式が完全に省略されている場合、条件は true であると仮定されます。
  4. +
  5. statement が実行されます。複数の式を実行するにはブロック文 ({ ... }) を使用して文をグループ化してください。
  6. +
  7. 更新式 incrementExpression があれば実行されます。そしてコントロールがステップ 2 に戻ります。
  8. +
+


+ 次の関数には、スクローリングリスト(複数選択できる Select オブジェクト)で選択されたオプションの数を数える for 文が含まれています。for 文では変数 i が宣言され、それが 0 に初期化されています。iSelect オブジェクトのオプションの個数より小さいかをチェックし、続く if 文を実行し、ループが 1 回りしたら i を 1 だけ増加させます。

+
<script type="text/javascript">//<![CDATA[
+
+function howMany(selectObject) {
+   var numberSelected = 0;
+   for (var i = 0; i < selectObject.options.length; i++) {
+      if (selectObject.options[i].selected)
+         numberSelected++;
+   }
+   return numberSelected;
+}
+
+//]]></script>
+<form name="selectForm">
+   <p>
+      <strong>Choose some music types, then click the button below:</strong>
+      <br/>
+      <select name="musicTypes" multiple="multiple">
+         <option selected="selected">R&B</option>
+         <option>Jazz</option>
+         <option>Blues</option>
+         <option>New Age</option>
+         <option>Classical</option>
+         <option>Opera</option>
+      </select>
+   </p>
+   <p>
+      <input type="button" value="How many are selected?"
+         onclick="alert ('Number of options selected: ' + howMany(document.selectForm.musicTypes))"/>
+   </p>
+</form>
+
+

{{ PreviousNext("JavaScript/Guide/Loop_Statements", "JavaScript/Guide/Loop_Statements/do...while_Statement") }}

diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/index.html new file mode 100644 index 0000000000..54ef32d2c9 --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/index.html @@ -0,0 +1,17 @@ +--- +title: ループ文 +slug: Web/JavaScript/Guide/Loop_Statements +--- +

ループ文

+

ループは指定した条件が満たされている限り繰り返し実行されるコマンドのセットです。JavaScript は、label はもちろん、for、do while、while といったループ文をサポートしています(label 自体はループ文ではありませんが、これらの文とともに頻繁に使用されます)。さらに、break および continue 文をループ文の中で使うことができます。

+

さらに for...in 文も文を繰り返し実行しますが、これはオブジェクトの操作に使用します。オブジェクト操作文 をご覧ください。

+

ループ文は以下のとおりです。

+ +

{{ PreviousNext("JavaScript/Guide/Conditional_Statements", "JavaScript/Guide/Loop_Statements/for_Statement") }}

diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/label_statement/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/label_statement/index.html new file mode 100644 index 0000000000..d0b878455b --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/label_statement/index.html @@ -0,0 +1,19 @@ +--- +title: label 文 +slug: Web/JavaScript/Guide/Loop_Statements/label_Statement +--- +

label 文

+

label を使うと、そのプログラムのどこからでも参照できる、識別子を持った文を作ることができます。例えば、ラベルを使用してあるループに名前を付けると、break 文や continue 文を使用してプログラムがループを脱出するべきかそのまま実行を継続するべきかを示すことができます。

+

label 文は次のように使用します。

+
label :
+   statement
+
+

label の値は予約語でなければどんな JavaScript の識別子でも使用できます。ラベルを用いて名前を付ける statement はどんな文でも結構です。

+


+ この例では markLoop というラベルを用いて while ループに名前を付けています。

+
markLoop:
+while (theMark == true)
+   doSomething();
+}
+
+

{{ PreviousNext("JavaScript/Guide/Loop_Statements/while_Statement", "JavaScript/Guide/Loop_Statements/break_Statement") }}

diff --git a/files/ja/orphaned/web/javascript/guide/loop_statements/while_statement/index.html b/files/ja/orphaned/web/javascript/guide/loop_statements/while_statement/index.html new file mode 100644 index 0000000000..77fd191f75 --- /dev/null +++ b/files/ja/orphaned/web/javascript/guide/loop_statements/while_statement/index.html @@ -0,0 +1,35 @@ +--- +title: while 文 +slug: Web/JavaScript/Guide/Loop_Statements/while_Statement +--- +

while 文

+

while 文は、指定した条件が true に評価される限り文を実行します。while 文は次のように使用します。

+
while (condition)
+   statement
+
+

条件が false になるとループ内の statement の実行が停止し、ループの後に続く文にコントロールが渡されます。

+

ループの statement を実行する前に条件がテストされます。条件が true を返すと statement が実行され、再び条件がテストされます。条件が false を返すと、実行が停止され、while の後に続く文にコントロールが渡されます。

+

複数の文を実行するにはブロック文 ({ ... }) を用いて文をグループ化してください。

+

例 1
+ 次の while ループでは n が 3 より小さい限り反復されます。

+
n = 0;
+x = 0;
+while (n < 3) {
+   n++;
+   x += n;
+}
+
+

それぞれの反復で、ループは n をインクリメントし、その値を x に加えています。その結果、xn は次の値をとります。

+ +

第 3 段階が完了すると条件 n < 3 が true ではなくなっているため、ループは終了します。

+

例 2
+ 無限ループは避けてください。ループの条件が最終的には false になることを確認してください。そうしないとループが終了しなくなります。次の while ループ内の文は永久に実行されます。条件が決して false にならないためです。

+
while (true) {
+   alert("Hello, world");
+}
+
+

{{ PreviousNext("JavaScript/Guide/Loop_Statements/do...while_Statement", "JavaScript/Guide/Loop_Statements/label_Statement") }}

-- cgit v1.2.3-54-g00ecf