gpt4 book ai didi

javascript goto标签如何使用内部循环

转载 作者:行者123 更新时间:2023-11-30 00:09:03 27 4
gpt4 key购买 nike

for (var rows = 0; rows < 10; rows++) 
{
[lbl] topOfLoop:
if (row == 5 ) {
goto topOfLoop;
}else{
alert(row);
}

有没有办法在 Javascript 中做到这一点?

最佳答案

来自 label 的 MSN 文档

The labeled statement can be used with break or continue statements. It is prefixing a statement with an identifier which you can refer to.

var i, j;

loop1: for (i = 0; i < 3; i++) { //The first for statement is labeled "loop1"
loop2: for (j = 0; j < 3; j++) { //The second for statement is labeled "loop2"
if (i === 1 && j === 1) {
continue loop1;
}
document.write("i = " + i + ", j = " + j + '<br>');
}
}

关于javascript goto标签如何使用内部循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37275405/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com