04 cycle control

Loop control

while 和 for

<! DOCTYPE HTML> 
<HTML lang = " EN " > 
<head> 
    <Meta charset = " UTF-. 8 " > 
    <title> cycle control </ title> 
</ head> 
<body> 
    <Script type = " text / JavaScript " >
         //   the while three elements: the initial variables are updated determination condition variable 
        var NUM = . 1 , SUM = 0 ;
         the while (NUM <= 100 ) { 
            SUM + = NUM; 
            NUM ++ ; 
        } 
        the console.log (SUM);

        //and while the difference between do whie is executed once and then the first loop 
        var num2 = . 1 , SUM2 = 0 ;
         do { 
            SUM2 + = num2; 
            num2 ++ ; 
        } while (num2 <= 100 ); 
        the console.log (SUM2); 

        / / for traversal cycle 
        var sum3 = 0 ;
         for ( var I = . 1 ; I <= 100 ; I ++ ) { 
            sum3 + = I; 
        } 
        the console.log (sum3); 

        //Output right triangle browser 
        for ( var J = . 1 ; J <= . 6 ; J ++) { // the control of the number of rows 
           for ( var K = . 1 ; K <= J; K ++) { // control * 
               Document. Write ( " * " ); 
           } 
           document.write ( ' <br> ' ); 
        }
     </ Script> 
</ body> 
</ HTML>

 

Guess you like

Origin www.cnblogs.com/znyyy/p/11095882.html