Loop classification {
for
while
do ( ) while
}
A, for loop and the nested for loop
for round robin format eg:
<script> var sim = 0; for(var i=1;i<=100;i++){ sum+=i; } console.log(sum) </script>
The expression "i = 1" total run 1, run before the loop;
The expression "i <= 100" determines whether a condition is satisfied iteration of the loop, if so, how many times the loop is executed many times, out of the loop body is not satisfied;
The expression "i ++" self-increment operator.
for nested loop eg:
< Script > for ( var I = . 1 ; I <= . 3 ; I ++ ) { document.write ( ' outer loop of the loop ' + I + ' result times <br /> ' ); for ( var J = . 1 ; J <= 2 ; J ++ ) { document.write ( ' inner loop cycle ' + J + ' times results <br /> ' ); } document.write ( ' <HR /> ' ); </ Script > // once the outer loop, the inner loop a
Two, the while loop EG ( first determination condition, and then performs content loop )
<Script> var = I. 1; // initial value while (i <= 20) { // condition document.write (I); document.write ( '<br />'); I = + 10; } </ Script > // output value is 1; 11;
Three, do () while loop eg ( performed first in the do, and then determine the conditions, conditions continue to cycle, not recycled when conditions are not met )
do{ document.write('hello meizi'); }while(false);
Four, break and continue
a: break: break out of this loop, the current loop ends, the loop performed behind the statement;
b: continue: continue to cycle out of the current to continue the next cycle;