Home > Article > Web Front-end > js about nested for loop examples
How to break or continue the outer for loop in the inner layer of javascript nested for loop? It's very simple. You can add a label to the outer for loop, and just add the corresponding label name when breaking or continuing:
outer: // 给外层的for循环加上标签,取名为outer for(var i=0;i<4;i++){ inner: for(var j=0;j<4;j++){ if(j>=3){ break outer } console.log("i="+i+" j="+j) } }
Related recommendations:
for in JS How to solve the loop closure problem
JavaScript for loop understanding of if judgment statements
The above is the detailed content of js about nested for loop examples. For more information, please follow other related articles on the PHP Chinese website!