We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在进行双重 for 循环计算时,我们希望满足条件跳出循环,以免不必要的资源浪费。
for
此时,我们就可以使用 label 和 continue/break 配合使用。
label
continue/break
firstLoop: for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { if (i === j) { continue firstLoop; // 继续 firstLoop 循环 // break firstLoop; // 中止 firstLoop 循环 } console.log(`i = ${i}, j = ${j}`); } } // 输出 i = 1, j = 0 i = 2, j = 0 i = 2, j = 1 for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { if (i === j) { continue } console.log(`i = ${i}, j = ${j}`); } } // 输出 i = 0, j = 1 i = 0, j = 2 i = 1, j = 0 i = 1, j = 2 i = 2, j = 0 i = 2, j = 1
参考:
https://juejin.im/post/5d1716e4f265da1bbc6fea1e
The text was updated successfully, but these errors were encountered:
No branches or pull requests
在进行双重
for
循环计算时,我们希望满足条件跳出循环,以免不必要的资源浪费。此时,我们就可以使用
label
和continue/break
配合使用。参考:
https://juejin.im/post/5d1716e4f265da1bbc6fea1e
The text was updated successfully, but these errors were encountered: