JavaScript013,while,do_while循环

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JavaScript while循环</title>
    </head>
    <body>
        <h3>while循环 和 do_while循环</h3>
        while循环:<span id="demo"></span>
        </br></br>
        do_while循环:<span the above mentioned id = "demo1" > </ span > 
        
        < Script of the type = "text / JavaScript" > 
            / * the while loop: as long as the conditions are met, would have been executed, the condition is false will not be executed * / 
            var i =  1 ;         // statement initializes variables i and 
            the while (i <=  . 5 ) {     // 1. the first performance, i = 1, i <= 5, set up condition, into the circulation 
                document.getElementById ( " Demo " ) .innerHTML =  " condition is satisfied, I performed "  + i +  " times! " ; // 2. output statement
                I ++ ;     // 3.i ++ (equivalent to i + 1 = 2), then back to the first step determination condition is satisfied to continue execution condition is not satisfied, out of the loop 
            } 
            
            / * the Do_While cycle: as a matter condition is not satisfied, both to perform at least once (because do_while statement is to be executed in front of the judge's statement) * / 
            do {     // 1. regardless of whether the conditions are met, they have to perform here 
                document.getElementById ( " demo1 " ) .innerHTML =  " i = 1; so i <0 condition is not satisfied, but I will execute it again! " ; 
                i ++ ; // 2. then perform here 
            }
             the while (i < 0 ); // 3. Finally, execute judgment statement, conditions are not met then exit the loop; 
        </script>
    </body>
</html>

Guess you like

Origin www.cnblogs.com/zhou0910/p/12147293.html