loop control

break: used to terminate the loop, placed in the curly braces of the condition; the loop will be terminated when the condition is met.

Terminate loop example

    for(var i=0;i<10;i++){
        if(i==6){
            break; // terminate the loop
        }
        println(i);
    }
    function println(a) {
        document.write(a+"<br>");
    }

  


continue: used to jump out of the loop, the loop that satisfies the condition will be skipped after use, and the subsequent loop will continue to execute

 

out of this cycle

    var i = 1;

    while(i<10){
        i=i+1;
        if (i==5){
            continue;//Jump out of this loop
        }
        println("Current traversal number: "+i);
    }
    function  println(a) {
        document.write(a+"<br>")
    }

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324928976&siteId=291194637