while loops, for loops

while loop

It is true while loop will execute the code block cyclic specified conditions.

If you forget to add conditions to the value of the variables used in the cycle never ends. This can cause the browser to Ken Ben collapse.

grammar

the while (condition) 
{ 
    code needs to be executed 
}

 

Examples

Cycle of the present embodiment will continue to run as long as the variable i is less than 5:

function myFunction(){
    var x="",i=0;
    while (i<5){
        x=x + "该数字为 " + i + "<br>";
        i++;
    }
    document.write(x)
}

 

Guess you like

Origin www.cnblogs.com/MrZhujl/p/11882800.html