continue跳出多重循环

做 leetcode809 时,碰到了continue需要跳出二层循环的场景,我不知道如何使用二层循环,于是多建了一个标识符。实际上结合out就可以实现。

1
2
3
4
5
6
out:for (const word of words) {
let m = word.length, i = 0, j = 0
while (i < n && j < m) {
if (s[i] != word[j]) continue out
}
}

不加out会跳出while,继续执行for…of循环。

加上out会直接跳出out指向的循环(即for…of循环)


continue跳出多重循环
http://example.com/2022/11/25/跳出多重循环/
Author
John Doe
Posted on
November 25, 2022
Licensed under