当前位置:网站首页>JS label syntax jumps out of multiple loops

JS label syntax jumps out of multiple loops

2020-11-09 23:48:14 Ah ho boy

https://zhuanlan.zhihu.com/p/32051963

Don't abuse it .... The best end result of this thing is to abandon it ... 

Me too. Before vue that rfc Only to learn that js There are also such things

Yes c/c++ goto It's internal

let i = 0
let j = 0
out: for (i = 0; i < 3; i++) {
  console.log("i", i, j)
  for (j = 0; j < 3; j++) {
    console.log("j", i, j)
    if (j === 1) {
    //   break
      break out;
    }
  }
}
console.log("end")
/*
i 0 0
j 0 0
j 0 1
i 1 1
j 1 0
j 1 1
i 2 1
j 2 0
j 2 1
end
*/

/*
i 0 0
j 0 0
j 0 1
end

*/

 

版权声明
本文为[Ah ho boy]所创,转载请带上原文链接,感谢