Jump to content
  • 0

Двойной цикл


uefa
 Share

Question

Подскажите, пожалуйста, как можно выйти из двойного цикла. Пробовал так и ничего не получилось:

function search_Array(point) {
for (var i = 0; i < mainArray.length; i++) {
alert(i);
for (var j = 0; j < mainArray[i].option.length; j++) {
alert(j);
if (mainArray[i].option[j].value == point) {
alert (mainArray[i].option[j].value);
break endLoop;
}
}
}
endLoop:
return [i, j];
}

Можно, конечно, по окончанию первого цикла еще раз вставить такую же проверку (if (mainArray.option[j].value == point) ), но как-то криво выглядит. Помогите. Спасибо.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
return вместо break поставь.

endLoop - это что?

Да вот пример похожий из сети вытащил:

The keyword break exits out of loop structures and switch statement.

When a label is used, JavaScript completely breaks out of the area designated by label.

To label a statement, place the label name followed by a colon (:).

Labels are useful when working with nested loops.

 <html>
<SCRIPT LANGUAGE='JavaScript'>
<!--
forLoop1:
for (var counter1 = 1; counter1 <= 5; counter1++)
{
for (var counter2 = 1; counter2 <= 5; counter2++)
{
document.write("Counter1=",counter1);
document.write(" Counter2=",counter2,"<BR>");
if (counter2 == 3)
break;
if (counter1 == 3)
break forLoop1;
}
}
document.write("All done!");
//-->
</SCRIPT>
</html>

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy