1<script type= "Text/javascript" >2 3 //loop for Loop4 //looping through a function (executing a piece of code)5 //four elements 1. Loop initial value 2. Loop condition 3. State Change 4. Loop Body6 7 8 //first for Loop9 //The first entry for the for Loop executes the initial value i=0, then the condition judgment i<10; the Loop body alert (i) and the state change is performed i++Ten //The second cycle is a direct condition to determine the i<10; cyclic body alert (i), and the re-state changes i++ to loop back and forth until the condition is judged i<10; One for(vari=0;i<10;i++) A { - alert (i); - the } - - - + - + //i++; equivalent to i=i+1; A //++i; equivalent to i=i+1; at - varA = 0; - varb = a++;//If you use a++, first give the value of a to B, itself a plus one if you use ++a A to add a first, and then a value to B - - alert (b); - in - to + //for loop example output 100 of its number and even - the varJS = "";//store Odd * $ varOS = "";//Storing even numbersPanax Notoginseng - for(vari=1;i<100;i++)//I starting from 1; I less than 100, once per cycle plus one i++ the { + if(i%2 = = 0) A { theOS = os+i+ "|";//even + } - Else $ { $js = js+i+ "|";//Odd - } - the - }Wuyi thealert (OS);//Output Even -alert (JS);//output Odd Wu - About $ //example takes 100 or 7 related numbers. - /*alert (parseint (78/10) ==7);*/ - - vars = ""; A + for(vari=0;i<100; i++) the{//the relationship between the two - if(I%7==0 | | i%10==7 | | parseint (I/10) ==7) $ { thes = s+i+ "|"; the the } the - } in the alert (s); the About the the the + - the //Example! Bayi the //sum of numbers within 100 the - varsum = 0 - for(vari = 0; i<100; i++) the { the //sum = Sum +i; the theSum + =i; - } the alert (sum); the the //ask for factorial within 1094 varJC = 1; the for(varI=1; i<10; i++) the { theJC = jc*I98 } About alert (JC); - 101 102 103 104 //Output Multiplication Table the 106 107 vars = "";108 109 for(varI=1; i<10; i++) the {111 for(varJ=1; j<10;j++) the {113 if(j>=i) the { the varCJ = i*J; thes = s+i+ "multiplied by" +j+ "equals" +cj+ "|";117 118 }119 - }121 122 123 }124 the 126 alert (s);127 - 129 the 131 //basketball fell from 5 meters high, the height of each bounce is the original 30%, after a few bounces, the height of the blue ball is 0.01 meters. the varGD = 5;//Basketball Initial Height133 varCS =0;134 while(true)135 {136cs++;137GD = gd*0.3;138 if(gd<0.1)139 { $ Break;141 }142 }143 alert (CS);144 145 146 147 148</script>149 Max 153</body>154
For Loop example