Home  >  Article  >  Web Front-end  >  js about nested for loop examples

js about nested for loop examples

小云云
小云云Original
2018-02-26 15:12:402798browse

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

Four kinds of for loops in js

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn