Visit Mozilla.org

Dokumentacja języka JavaScript 1.5:Polecenia:continue

z Mozilla Developer Center, polskiego centrum programistów Mozilli.

UWAGA: Tłumaczenie tej strony nie zostało zakończone.
Może być ona niekompletna lub wymagać korekty.
Chcesz pomóc? | Dokończ tłumaczenie | Sprawdź ortografię | Więcej takich stron...

Spis treści

[edytuj] Podsumowanie

Terminates execution of the statements in the current iteration of the current or labelled loop, and continues execution of the loop with the next iteration.

Instrukcja
Zaimplementowana w: JavaScript 1.0, NES 2.0
Wersja ECMA: ECMA-262 (for the unlabeled version)

ECMA-262, Edycja 3 (for the labeled version)

[edytuj] Składnia

continue [label];

[edytuj] Parametry

label 
Identifier associated with the label of the statement.

[edytuj] Opis

In contrast to the break statement, continue does not terminate the execution of the loop entirely: instead,

  • In a while loop, it jumps back to the condition.
  • In a for loop, it jumps to the update expression.

The continue statement can include an optional label that allows the program to jump to the next iteration of a labelled loop statement instead of the current loop. In this case, the continue statement needs to be nested within this labelled statement.

[edytuj] Przykłady

[edytuj] Przykład: Zastosowanie continue z while

Następujące przykład pokazuje pętlę while, która posiada instrukcję continue tak, że zostanie wykonana w momencie, gdy wartość i jest 3. Tak więc, n pobiera wartości 1, 3, 7 i 12.

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

[edytuj] Przykład: Zastosowanie continue z etykietą

In the following example, a statement labeled checkiandj contains a statement labeled checkj. If continue is encountered, the program continues at the top of the checkj statement. Each time continue is encountered, checkj reiterates until its condition returns false. When false is returned, the remainder of the checkiandj statement is completed.

If continue had a label of checkiandj, the program would continue at the top of the checkiandj statement.

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>");
}

[edytuj] Zobacz także

break, etykieta